mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-29 01:20:02 +03:00
Wrap test in try/finally, cleanup duration determination
This commit is contained in:
parent
72fbefd853
commit
957b39fa8d
|
@ -363,10 +363,8 @@ class APIView(View):
|
||||||
if duration is not None
|
if duration is not None
|
||||||
]
|
]
|
||||||
|
|
||||||
if durations:
|
duration = max(durations) if durations else None
|
||||||
self.throttled(request, max(durations))
|
self.throttled(request, duration)
|
||||||
else:
|
|
||||||
self.throttled(request, None)
|
|
||||||
|
|
||||||
def determine_version(self, request, *args, **kwargs):
|
def determine_version(self, request, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -168,16 +168,17 @@ class ThrottlingTests(TestCase):
|
||||||
assert int(response['retry-after']) == 60
|
assert int(response['retry-after']) == 60
|
||||||
|
|
||||||
previous_rate = User3SecRateThrottle.rate
|
previous_rate = User3SecRateThrottle.rate
|
||||||
User3SecRateThrottle.rate = '1/sec'
|
try:
|
||||||
|
User3SecRateThrottle.rate = '1/sec'
|
||||||
|
|
||||||
for dummy in range(24):
|
for dummy in range(24):
|
||||||
response = MockView_DoubleThrottling.as_view()(request)
|
response = MockView_DoubleThrottling.as_view()(request)
|
||||||
|
|
||||||
assert response.status_code == 429
|
assert response.status_code == 429
|
||||||
assert int(response['retry-after']) == 60
|
assert int(response['retry-after']) == 60
|
||||||
|
finally:
|
||||||
# reset
|
# reset
|
||||||
User3SecRateThrottle.rate = previous_rate
|
User3SecRateThrottle.rate = previous_rate
|
||||||
|
|
||||||
def ensure_response_header_contains_proper_throttle_field(self, view, expected_headers):
|
def ensure_response_header_contains_proper_throttle_field(self, view, expected_headers):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user