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
e9d371f2
Commit
e9d371f2
authored
Jan 09, 2017
by
Artem Muterko
Committed by
Tom Christie
Jan 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add couple of basic tests for SimpleRateThrottle (#4800)
parent
b6b2c4bb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
1 deletions
+20
-1
tests/test_throttling.py
+20
-1
No files found.
tests/test_throttling.py
View file @
e9d371f2
...
...
@@ -3,15 +3,17 @@ Tests for the throttling implementations in the permissions module.
"""
from
__future__
import
unicode_literals
import
pytest
from
django.contrib.auth.models
import
User
from
django.core.cache
import
cache
from
django.core.exceptions
import
ImproperlyConfigured
from
django.test
import
TestCase
from
rest_framework.response
import
Response
from
rest_framework.settings
import
api_settings
from
rest_framework.test
import
APIRequestFactory
from
rest_framework.throttling
import
(
BaseThrottle
,
ScopedRateThrottle
,
UserRateThrottle
BaseThrottle
,
ScopedRateThrottle
,
SimpleRateThrottle
,
UserRateThrottle
)
from
rest_framework.views
import
APIView
...
...
@@ -354,3 +356,20 @@ class XffUniqueMachinesTest(XffTestingBase):
self
.
view
(
self
.
request
)
self
.
request
.
META
[
'HTTP_X_FORWARDED_FOR'
]
=
'0.0.0.0, 7.7.7.7, 2.2.2.2'
assert
self
.
view
(
self
.
request
)
.
status_code
==
200
class
SimpleRateThrottleTests
(
TestCase
):
def
test_throttle_raises_error_if_scope_is_missing
(
self
):
with
pytest
.
raises
(
ImproperlyConfigured
):
SimpleRateThrottle
()
def
test_throttle_raises_error_if_rate_is_missing
(
self
):
SimpleRateThrottle
.
scope
=
'test'
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
)
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