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
Example #2
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
 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
Example #4
0
 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
Example #5
0
 def test_allow_request_returns_true_if_key_is_none(self):
     throttle = SimpleRateThrottle()
     throttle.rate = 'some rate'
     throttle.get_cache_key = lambda *args: None
     assert throttle.allow_request(request={}, view={}) is True
Example #6
0
 def test_get_cache_key_raises_not_implemented_error(self):
     with pytest.raises(NotImplementedError):
         SimpleRateThrottle().get_cache_key({}, {})
Example #7
0
 def test_allow_request_returns_true_if_rate_is_none(self):
     assert SimpleRateThrottle().allow_request(request={}, view={}) is True
Example #8
0
 def test_parse_rate_returns_tuple_with_none_if_rate_not_provided(self):
     rate = SimpleRateThrottle().parse_rate(None)
     assert rate == (None, None)
Example #9
0
 def test_throttle_raises_error_if_rate_is_missing(self):
     SimpleRateThrottle.scope = 'invalid scope'
     with pytest.raises(ImproperlyConfigured):
         SimpleRateThrottle()
Example #10
0
 def test_get_rate_raises_error_if_scope_is_missing(self):
     throttle = SimpleRateThrottle()
     with pytest.raises(ImproperlyConfigured):
         throttle.scope = None
         throttle.get_rate()
 def test_throttle_raises_error_if_scope_is_missing(self):
     with pytest.raises(ImproperlyConfigured):
         SimpleRateThrottle()
 def test_allow_request_returns_true_if_key_is_none(self):
     throttle = SimpleRateThrottle()
     throttle.rate = 'some rate'
     throttle.get_cache_key = lambda *args: None
     assert throttle.allow_request(request={}, view={}) is True
 def test_get_rate_raises_error_if_scope_is_missing(self):
     throttle = SimpleRateThrottle()
     with pytest.raises(ImproperlyConfigured):
         throttle.scope = None
         throttle.get_rate()