From dd11bd42a2bfec3d5799509f22405f04eee07e85 Mon Sep 17 00:00:00 2001 From: Artem Muterko Date: Wed, 11 Jan 2017 22:39:48 +0200 Subject: [PATCH] Add remaining tests for SimpleRateThrottle (#4803) --- tests/test_throttling.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_throttling.py b/tests/test_throttling.py index 267020f52..f5b434458 100644 --- a/tests/test_throttling.py +++ b/tests/test_throttling.py @@ -397,3 +397,20 @@ class SimpleRateThrottleTests(TestCase): throttle.rate = 'some rate' throttle.get_cache_key = lambda *args: None assert throttle.allow_request(request={}, view={}) is True + + def test_wait_returns_correct_waiting_time_without_history(self): + throttle = SimpleRateThrottle() + throttle.num_requests = 1 + throttle.duration = 60 + throttle.history = [] + waiting_time = throttle.wait() + assert isinstance(waiting_time, float) + assert waiting_time == 30.0 + + def test_wait_returns_none_if_there_are_no_available_requests(self): + throttle = SimpleRateThrottle() + throttle.num_requests = 1 + throttle.duration = 60 + throttle.now = throttle.timer() + throttle.history = [throttle.timer() for _ in range(3)] + assert throttle.wait() is None