@@ -194,6 +194,8 @@ class ScopedRateThrottleTests(TestCase):
194
194
"""
195
195
196
196
def setUp (self ):
197
+ self .throttle = ScopedRateThrottle ()
198
+
197
199
class XYScopedRateThrottle (ScopedRateThrottle ):
198
200
TIMER_SECONDS = 0
199
201
THROTTLE_RATES = {'x' : '3/min' , 'y' : '1/min' }
@@ -293,6 +295,18 @@ def test_unscoped_view_not_throttled(self):
293
295
response = self .unscoped_view (request )
294
296
assert response .status_code == 200
295
297
298
+ def test_get_cache_key_returns_correct_key_if_user_is_authenticated (self ):
299
+ class DummyView (object ):
300
+ throttle_scope = 'user'
301
+
302
+ request = Request (HttpRequest ())
303
+ user = User .objects .create (username = 'test' )
304
+ force_authenticate (request , user )
305
+ request .user = user
306
+ self .throttle .allow_request (request , DummyView ())
307
+ cache_key = self .throttle .get_cache_key (request , view = DummyView ())
308
+ assert cache_key == 'throttle_user_%s' % user .pk
309
+
296
310
297
311
class XffTestingBase (TestCase ):
298
312
def setUp (self ):
@@ -435,18 +449,3 @@ def test_get_cache_key_returns_correct_value(self):
435
449
request = Request (HttpRequest ())
436
450
cache_key = self .throttle .get_cache_key (request , view = {})
437
451
assert cache_key == 'throttle_anon_None'
438
-
439
-
440
- class UserRateThrottleTests (TestCase ):
441
-
442
- def setUp (self ):
443
- self .throttle = UserRateThrottle ()
444
-
445
- def test_get_cache_key_returns_correct_key_if_user_is_authenticated (self ):
446
- request = Request (HttpRequest ())
447
- user = User .objects .create (username = 'test' )
448
- force_authenticate (request , user )
449
- request .user = user
450
-
451
- cache_key = self .throttle .get_cache_key (request , view = {})
452
- assert cache_key == 'throttle_user_%s' % user .pk
0 commit comments