Skip to content

Commit dd11bd4

Browse files
arthur-github-usertomchristie
authored andcommitted
Add remaining tests for SimpleRateThrottle (encode#4803)
1 parent 14baf7e commit dd11bd4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/test_throttling.py

+17
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,20 @@ def test_allow_request_returns_true_if_key_is_none(self):
397397
throttle.rate = 'some rate'
398398
throttle.get_cache_key = lambda *args: None
399399
assert throttle.allow_request(request={}, view={}) is True
400+
401+
def test_wait_returns_correct_waiting_time_without_history(self):
402+
throttle = SimpleRateThrottle()
403+
throttle.num_requests = 1
404+
throttle.duration = 60
405+
throttle.history = []
406+
waiting_time = throttle.wait()
407+
assert isinstance(waiting_time, float)
408+
assert waiting_time == 30.0
409+
410+
def test_wait_returns_none_if_there_are_no_available_requests(self):
411+
throttle = SimpleRateThrottle()
412+
throttle.num_requests = 1
413+
throttle.duration = 60
414+
throttle.now = throttle.timer()
415+
throttle.history = [throttle.timer() for _ in range(3)]
416+
assert throttle.wait() is None

0 commit comments

Comments
 (0)