diff options
| author | Jeremy Satterfield | 2013-08-13 15:31:58 -0500 |
|---|---|---|
| committer | Jeremy Satterfield | 2013-08-13 15:31:58 -0500 |
| commit | 1d8a80f5cc41f157403771439f15c9b7d615a43b (patch) | |
| tree | a8b97df1665f9eb4cdab9d6a2a8585cf1094d2c6 /rest_framework/tests/test_throttling.py | |
| parent | 999056cde1c6355d5ca036f109b35b41cb9d47cc (diff) | |
| download | django-rest-framework-1d8a80f5cc41f157403771439f15c9b7d615a43b.tar.bz2 | |
don't set X-Throttle-Wait-Second header if throttle wait is None
Diffstat (limited to 'rest_framework/tests/test_throttling.py')
| -rw-r--r-- | rest_framework/tests/test_throttling.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/rest_framework/tests/test_throttling.py b/rest_framework/tests/test_throttling.py index 19bc691a..41bff692 100644 --- a/rest_framework/tests/test_throttling.py +++ b/rest_framework/tests/test_throttling.py @@ -7,7 +7,7 @@ from django.contrib.auth.models import User from django.core.cache import cache from rest_framework.test import APIRequestFactory from rest_framework.views import APIView -from rest_framework.throttling import UserRateThrottle, ScopedRateThrottle +from rest_framework.throttling import BaseThrottle, UserRateThrottle, ScopedRateThrottle from rest_framework.response import Response @@ -21,6 +21,14 @@ class User3MinRateThrottle(UserRateThrottle): scope = 'minutes' +class NonTimeThrottle(BaseThrottle): + def allow_request(self, request, view): + if not hasattr(self.__class__, 'called'): + self.__class__.called = True + return True + return False + + class MockView(APIView): throttle_classes = (User3SecRateThrottle,) @@ -35,6 +43,13 @@ class MockView_MinuteThrottling(APIView): return Response('foo') +class MockView_NonTimeThrottling(APIView): + throttle_classes = (NonTimeThrottle,) + + def get(self, request): + return Response('foo') + + class ThrottlingTests(TestCase): def setUp(self): """ @@ -140,6 +155,22 @@ class ThrottlingTests(TestCase): (80, None) )) + def test_non_time_throttle(self): + """ + Ensure for second based throttles. + """ + request = self.factory.get('/') + + self.assertFalse(hasattr(MockView_NonTimeThrottling.throttle_classes[0], 'called')) + + response = MockView_NonTimeThrottling.as_view()(request) + self.assertFalse('X-Throttle-Wait-Seconds' in response) + + self.assertTrue(MockView_NonTimeThrottling.throttle_classes[0].called) + + response = MockView_NonTimeThrottling.as_view()(request) + self.assertFalse('X-Throttle-Wait-Seconds' in response) + class ScopedRateThrottleTests(TestCase): """ |
