Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
34cc63d9
Unverified
Commit
34cc63d9
authored
Oct 17, 2017
by
Gabe Mulley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove slow and flaky throttling tests
parent
7d6aa950
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
63 deletions
+2
-63
common/djangoapps/enrollment/tests/test_views.py
+2
-63
No files found.
common/djangoapps/enrollment/tests/test_views.py
View file @
34cc63d9
...
...
@@ -4,7 +4,6 @@ Tests for user enrollment.
import
datetime
import
itertools
import
json
import
time
import
unittest
import
ddt
...
...
@@ -160,8 +159,6 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
self
.
rate_limit_config
.
enabled
=
False
self
.
rate_limit_config
.
save
()
self
.
start_time
=
time
.
time
()
self
.
elapsed_seconds
=
0
throttle
=
EnrollmentUserThrottle
()
self
.
rate_limit
,
__
=
throttle
.
parse_rate
(
throttle
.
rate
)
...
...
@@ -537,14 +534,8 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
self
.
assertEqual
(
resp
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertIn
(
"No course "
,
resp
.
content
)
def
fake_timer
(
self
):
return
self
.
start_time
+
self
.
elapsed_seconds
@patch.object
(
EnrollmentUserThrottle
,
'timer'
)
def
test_enrollment_throttle_for_user
(
self
,
mock_timer
):
def
test_enrollment_throttle_for_user
(
self
):
"""Make sure a user requests do not exceed the maximum number of requests"""
mock_timer
.
side_effect
=
self
.
fake_timer
self
.
rate_limit_config
.
enabled
=
True
self
.
rate_limit_config
.
save
()
CourseModeFactory
.
create
(
...
...
@@ -553,62 +544,10 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
mode_display_name
=
CourseMode
.
DEFAULT_MODE_SLUG
,
)
for
attempt
in
xrange
(
self
.
rate_limit
+
10
):
self
.
elapsed_seconds
+=
0.01
# simulate 10 ms delay between requests
for
attempt
in
xrange
(
self
.
rate_limit
+
2
):
expected_status
=
status
.
HTTP_429_TOO_MANY_REQUESTS
if
attempt
>=
self
.
rate_limit
else
status
.
HTTP_200_OK
self
.
assert_enrollment_status
(
expected_status
=
expected_status
)
@patch.object
(
EnrollmentUserThrottle
,
'timer'
)
def
test_enrollment_throttle_for_staff_user
(
self
,
mock_timer
):
""" Make sure throttle rate is higher for staff users """
mock_timer
.
side_effect
=
self
.
fake_timer
self
.
rate_limit_config
.
enabled
=
True
self
.
rate_limit_config
.
save
()
self
.
client
.
logout
()
staff_user
=
UserFactory
.
create
(
password
=
self
.
PASSWORD
,
is_staff
=
True
)
self
.
client
.
login
(
username
=
staff_user
.
username
,
password
=
self
.
PASSWORD
)
CourseModeFactory
(
course_id
=
self
.
course
.
id
,
mode_slug
=
CourseMode
.
DEFAULT_MODE_SLUG
,
mode_display_name
=
CourseMode
.
DEFAULT_MODE_SLUG
,
)
throttle
=
EnrollmentUserThrottle
()
throttle
.
scope
=
'staff'
rate_limit
,
__
=
throttle
.
parse_rate
(
throttle
.
get_rate
())
# Make enough requests to reach the rate limit
for
attempt
in
xrange
(
rate_limit
):
self
.
elapsed_seconds
+=
0.01
# simulate a 10 ms delay between requests
self
.
assert_enrollment_status
(
username
=
staff_user
.
username
,
expected_status
=
status
.
HTTP_200_OK
)
# Once the limit is reached, subsequent requests should fail
for
attempt
in
xrange
(
50
):
self
.
elapsed_seconds
+=
0.01
# simulate a 10 ms delay between requests
self
.
assert_enrollment_status
(
username
=
staff_user
.
username
,
expected_status
=
status
.
HTTP_429_TOO_MANY_REQUESTS
)
# Once enough time has passed, requests should succeed again
self
.
elapsed_seconds
=
60.1
self
.
assert_enrollment_status
(
username
=
staff_user
.
username
,
expected_status
=
status
.
HTTP_200_OK
)
@patch.object
(
EnrollmentUserThrottle
,
'timer'
)
def
test_enrollment_throttle_for_service
(
self
,
mock_timer
):
"""Make sure a service can call the enrollment API as many times as needed. """
mock_timer
.
side_effect
=
self
.
fake_timer
self
.
rate_limit_config
.
enabled
=
True
self
.
rate_limit_config
.
save
()
CourseModeFactory
.
create
(
course_id
=
self
.
course
.
id
,
mode_slug
=
CourseMode
.
DEFAULT_MODE_SLUG
,
mode_display_name
=
CourseMode
.
DEFAULT_MODE_SLUG
,
)
for
__
in
xrange
(
self
.
rate_limit
+
10
):
self
.
elapsed_seconds
+=
0.01
# simulate a 10 ms delay between requests
self
.
assert_enrollment_status
(
as_server
=
True
)
def
test_create_enrollment_with_mode
(
self
):
"""With the right API key, create a new enrollment with a mode set other than the default."""
# Create a professional ed course mode.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment