Beispiel #1
0
 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')
Beispiel #2
0
 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)
Beispiel #3
0
 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')
Beispiel #4
0
 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')