def test_view_not_in_cache(self, cache_get, cache_set): decorator = decorators.throttle_view(methods=['GET'], duration=30) mocked = decorator(dummy_view) response = mocked(self.request) cache_get.assert_called_with(self.key) cache_set.assert_called_with(self.key, True, 30) eq_(response, 'ok')
def test_prefix_is_used(self, cache_get, cache_set): decorator = decorators.throttle_view( methods=['GET'], duration=30, prefix='FOO') mocked = decorator(dummy_view) mocked(self.request) key = 'FOO%s' % self.key cache_get.assert_called_with(key) eq_(cache_set.called, False)
def test_other_method_in_cache(self, cache_get, cache_set): decorator = decorators.throttle_view( methods=['POST', 'PUT'], duration=30) mocked = decorator(dummy_view) response = mocked(self.request) eq_(cache_get.called, False) eq_(cache_set.called, False) eq_(response, 'ok')
def test_view_in_cache(self, cache_get, cache_set): decorator = decorators.throttle_view(methods=['GET'], duration=30) mocked = decorator(dummy_view) response = mocked(self.request) cache_get.assert_called_with(self.key) eq_(cache_set.called, False) eq_(response.status_code, 503) eq_(response['Retry-After'], '30')