mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Throttle tests fix (#4810)
This commit is contained in:
parent
b4a9a1b9a3
commit
c686749eef
|
@ -194,6 +194,8 @@ class ScopedRateThrottleTests(TestCase):
|
|||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.throttle = ScopedRateThrottle()
|
||||
|
||||
class XYScopedRateThrottle(ScopedRateThrottle):
|
||||
TIMER_SECONDS = 0
|
||||
THROTTLE_RATES = {'x': '3/min', 'y': '1/min'}
|
||||
|
@ -293,6 +295,18 @@ class ScopedRateThrottleTests(TestCase):
|
|||
response = self.unscoped_view(request)
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_get_cache_key_returns_correct_key_if_user_is_authenticated(self):
|
||||
class DummyView(object):
|
||||
throttle_scope = 'user'
|
||||
|
||||
request = Request(HttpRequest())
|
||||
user = User.objects.create(username='test')
|
||||
force_authenticate(request, user)
|
||||
request.user = user
|
||||
self.throttle.allow_request(request, DummyView())
|
||||
cache_key = self.throttle.get_cache_key(request, view=DummyView())
|
||||
assert cache_key == 'throttle_user_%s' % user.pk
|
||||
|
||||
|
||||
class XffTestingBase(TestCase):
|
||||
def setUp(self):
|
||||
|
@ -435,18 +449,3 @@ class AnonRateThrottleTests(TestCase):
|
|||
request = Request(HttpRequest())
|
||||
cache_key = self.throttle.get_cache_key(request, view={})
|
||||
assert cache_key == 'throttle_anon_None'
|
||||
|
||||
|
||||
class UserRateThrottleTests(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.throttle = UserRateThrottle()
|
||||
|
||||
def test_get_cache_key_returns_correct_key_if_user_is_authenticated(self):
|
||||
request = Request(HttpRequest())
|
||||
user = User.objects.create(username='test')
|
||||
force_authenticate(request, user)
|
||||
request.user = user
|
||||
|
||||
cache_key = self.throttle.get_cache_key(request, view={})
|
||||
assert cache_key == 'throttle_user_%s' % user.pk
|
||||
|
|
Loading…
Reference in New Issue
Block a user