Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
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
django-rest-framework
Commits
c686749e
Commit
c686749e
authored
Jan 12, 2017
by
Artem Muterko
Committed by
Tom Christie
Jan 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throttle tests fix (#4810)
parent
b4a9a1b9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
15 deletions
+14
-15
tests/test_throttling.py
+14
-15
No files found.
tests/test_throttling.py
View file @
c686749e
...
...
@@ -194,6 +194,8 @@ class ScopedRateThrottleTests(TestCase):
"""
def
setUp
(
self
):
self
.
throttle
=
ScopedRateThrottle
()
class
XYScopedRateThrottle
(
ScopedRateThrottle
):
TIMER_SECONDS
=
0
THROTTLE_RATES
=
{
'x'
:
'3/min'
,
'y'
:
'1/min'
}
...
...
@@ -293,6 +295,18 @@ class ScopedRateThrottleTests(TestCase):
response
=
self
.
unscoped_view
(
request
)
assert
response
.
status_code
==
200
def
test_get_cache_key_returns_correct_key_if_user_is_authenticated
(
self
):
class
DummyView
(
object
):
throttle_scope
=
'user'
request
=
Request
(
HttpRequest
())
user
=
User
.
objects
.
create
(
username
=
'test'
)
force_authenticate
(
request
,
user
)
request
.
user
=
user
self
.
throttle
.
allow_request
(
request
,
DummyView
())
cache_key
=
self
.
throttle
.
get_cache_key
(
request
,
view
=
DummyView
())
assert
cache_key
==
'throttle_user_
%
s'
%
user
.
pk
class
XffTestingBase
(
TestCase
):
def
setUp
(
self
):
...
...
@@ -435,18 +449,3 @@ class AnonRateThrottleTests(TestCase):
request
=
Request
(
HttpRequest
())
cache_key
=
self
.
throttle
.
get_cache_key
(
request
,
view
=
{})
assert
cache_key
==
'throttle_anon_None'
class
UserRateThrottleTests
(
TestCase
):
def
setUp
(
self
):
self
.
throttle
=
UserRateThrottle
()
def
test_get_cache_key_returns_correct_key_if_user_is_authenticated
(
self
):
request
=
Request
(
HttpRequest
())
user
=
User
.
objects
.
create
(
username
=
'test'
)
force_authenticate
(
request
,
user
)
request
.
user
=
user
cache_key
=
self
.
throttle
.
get_cache_key
(
request
,
view
=
{})
assert
cache_key
==
'throttle_user_
%
s'
%
user
.
pk
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