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
87db5fbd
Commit
87db5fbd
authored
Jun 11, 2011
by
markotibold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented per user throttling
(commit to permissions.py fixes a bug that came out of the unittest)
parent
8ef333a2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
djangorestframework/tests/throttling.py
+10
-6
No files found.
djangorestframework/tests/throttling.py
View file @
87db5fbd
...
@@ -4,6 +4,7 @@ from django.conf.urls.defaults import patterns
...
@@ -4,6 +4,7 @@ from django.conf.urls.defaults import patterns
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.utils
import
simplejson
as
json
from
django.utils
import
simplejson
as
json
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.cache
import
cache
from
djangorestframework.compat
import
RequestFactory
from
djangorestframework.compat
import
RequestFactory
from
djangorestframework.views
import
View
from
djangorestframework.views
import
View
...
@@ -25,7 +26,8 @@ class ThrottlingTests(TestCase):
...
@@ -25,7 +26,8 @@ class ThrottlingTests(TestCase):
urls
=
'djangorestframework.tests.throttling'
urls
=
'djangorestframework.tests.throttling'
def
setUp
(
self
):
def
setUp
(
self
):
time
.
sleep
(
1
)
# make sure throttle is expired before next test
"""Reset the cache so that no throttles will be active"""
cache
.
clear
()
def
test_requests_are_throttled
(
self
):
def
test_requests_are_throttled
(
self
):
"""Ensure request rate is limited"""
"""Ensure request rate is limited"""
...
@@ -34,17 +36,19 @@ class ThrottlingTests(TestCase):
...
@@ -34,17 +36,19 @@ class ThrottlingTests(TestCase):
response
=
self
.
client
.
get
(
'/'
)
response
=
self
.
client
.
get
(
'/'
)
self
.
assertEqual
(
503
,
response
.
status_code
)
self
.
assertEqual
(
503
,
response
.
status_code
)
def
DISABLED
test_request_throttling_is_per_user
(
self
):
def
test_request_throttling_is_per_user
(
self
):
#Can not login user.....Dunno why...
#Can not login user.....Dunno why...
"""Ensure request rate is only limited per user, not globally"""
"""Ensure request rate is only limited per user, not globally"""
User
.
objects
.
create_user
(
'testuser'
,
'test'
,
'foo@bar.baz'
)
.
save
()
for
username
in
(
'testuser'
,
'another_testuser'
):
User
.
objects
.
create_user
(
'another_testuser'
,
'test'
,
'foo@bar.baz'
)
.
save
()
user
=
User
.
objects
.
create
(
username
=
username
)
user
.
set_password
(
'test'
)
user
.
save
()
self
.
assertTrue
(
self
.
client
.
login
(
username
=
'testuser'
,
password
=
'test'
))
self
.
assertTrue
(
self
.
client
.
login
(
username
=
'testuser'
,
password
=
'test'
)
,
msg
=
'Login Failed'
)
for
dummy
in
range
(
3
):
for
dummy
in
range
(
3
):
response
=
self
.
client
.
get
(
'/'
)
response
=
self
.
client
.
get
(
'/'
)
self
.
client
.
logout
()
self
.
client
.
logout
()
self
.
assertTrue
(
self
.
client
.
login
(
username
=
'another_testuser'
,
password
=
'test'
))
self
.
assertTrue
(
self
.
client
.
login
(
username
=
'another_testuser'
,
password
=
'test'
)
,
msg
=
'Login failed'
)
self
.
assertEqual
(
200
,
response
.
status_code
)
self
.
assertEqual
(
200
,
response
.
status_code
)
def
test_request_throttling_expires
(
self
):
def
test_request_throttling_expires
(
self
):
...
...
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