mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 16:24:18 +03:00
implemented per user throttling
(commit to permissions.py fixes a bug that came out of the unittest)
This commit is contained in:
parent
8ef333a29f
commit
87db5fbda5
|
@ -4,6 +4,7 @@ from django.conf.urls.defaults import patterns
|
|||
from django.test import TestCase
|
||||
from django.utils import simplejson as json
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.cache import cache
|
||||
|
||||
from djangorestframework.compat import RequestFactory
|
||||
from djangorestframework.views import View
|
||||
|
@ -25,7 +26,8 @@ class ThrottlingTests(TestCase):
|
|||
urls = 'djangorestframework.tests.throttling'
|
||||
|
||||
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):
|
||||
"""Ensure request rate is limited"""
|
||||
|
@ -34,17 +36,19 @@ class ThrottlingTests(TestCase):
|
|||
response = self.client.get('/')
|
||||
self.assertEqual(503, response.status_code)
|
||||
|
||||
def DISABLEDtest_request_throttling_is_per_user(self):
|
||||
def test_request_throttling_is_per_user(self):
|
||||
#Can not login user.....Dunno why...
|
||||
"""Ensure request rate is only limited per user, not globally"""
|
||||
User.objects.create_user('testuser', 'test', 'foo@bar.baz').save()
|
||||
User.objects.create_user('another_testuser', 'test', 'foo@bar.baz').save()
|
||||
for username in ('testuser', 'another_testuser'):
|
||||
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):
|
||||
response = self.client.get('/')
|
||||
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)
|
||||
|
||||
def test_request_throttling_expires(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user