diff options
| author | markotibold | 2011-06-11 01:49:22 +0200 | 
|---|---|---|
| committer | markotibold | 2011-06-11 01:49:22 +0200 | 
| commit | 87db5fbda550e0dc1b808d1df30700bf2606c10d (patch) | |
| tree | 1a8970235790e8fc7335f7e6cdeb45b8d9659673 /djangorestframework | |
| parent | 8ef333a29f1981b1ca4fa060998863285f408019 (diff) | |
| download | django-rest-framework-87db5fbda550e0dc1b808d1df30700bf2606c10d.tar.bz2 | |
implemented per user throttling
(commit to permissions.py fixes a bug that came out of the unittest)
Diffstat (limited to 'djangorestframework')
| -rw-r--r-- | djangorestframework/tests/throttling.py | 18 | 
1 files changed, 11 insertions, 7 deletions
diff --git a/djangorestframework/tests/throttling.py b/djangorestframework/tests/throttling.py index 189f3353..b33836a2 100644 --- a/djangorestframework/tests/throttling.py +++ b/djangorestframework/tests/throttling.py @@ -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() - -        self.assertTrue(self.client.login(username='testuser', password='test')) +        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'), 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):  | 
