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
66ffaaf5
Commit
66ffaaf5
authored
Jan 11, 2017
by
Artem Muterko
Committed by
Tom Christie
Jan 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests for Base and SimpleRate throttles (#4802)
parent
d6c6df40
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
4 deletions
+28
-4
tests/test_throttling.py
+28
-4
No files found.
tests/test_throttling.py
View file @
66ffaaf5
...
...
@@ -358,18 +358,42 @@ class XffUniqueMachinesTest(XffTestingBase):
assert
self
.
view
(
self
.
request
)
.
status_code
==
200
class
BaseThrottleTests
(
TestCase
):
def
test_allow_request_raises_not_implemented_error
(
self
):
with
pytest
.
raises
(
NotImplementedError
):
BaseThrottle
()
.
allow_request
(
request
=
{},
view
=
{})
class
SimpleRateThrottleTests
(
TestCase
):
def
test_throttle_raises_error_if_scope_is_missing
(
self
):
def
setUp
(
self
):
SimpleRateThrottle
.
scope
=
'anon'
def
test_get_rate_raises_error_if_scope_is_missing
(
self
):
throttle
=
SimpleRateThrottle
()
with
pytest
.
raises
(
ImproperlyConfigured
):
SimpleRateThrottle
()
throttle
.
scope
=
None
throttle
.
get_rate
()
def
test_throttle_raises_error_if_rate_is_missing
(
self
):
SimpleRateThrottle
.
scope
=
'
test
'
SimpleRateThrottle
.
scope
=
'
invalid scope
'
with
pytest
.
raises
(
ImproperlyConfigured
):
SimpleRateThrottle
()
def
test_parse_rate_returns_tuple_with_none_if_rate_not_provided
(
self
):
SimpleRateThrottle
.
scope
=
'anon'
rate
=
SimpleRateThrottle
()
.
parse_rate
(
None
)
assert
rate
==
(
None
,
None
)
def
test_allow_request_returns_true_if_rate_is_none
(
self
):
assert
SimpleRateThrottle
()
.
allow_request
(
request
=
{},
view
=
{})
is
True
def
test_get_cache_key_raises_not_implemented_error
(
self
):
with
pytest
.
raises
(
NotImplementedError
):
SimpleRateThrottle
()
.
get_cache_key
({},
{})
def
test_allow_request_returns_true_if_key_is_none
(
self
):
throttle
=
SimpleRateThrottle
()
throttle
.
rate
=
'some rate'
throttle
.
get_cache_key
=
lambda
*
args
:
None
assert
throttle
.
allow_request
(
request
=
{},
view
=
{})
is
True
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