Skip to content

Commit

Permalink
core.ratelimit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely committed May 19, 2016
1 parent 66827bf commit 0d1c373
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions spirit/core/tests/tests_utils_ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,18 @@ def one(request):
return request.is_limited

foo_cache = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
},
'foo': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'foo',
'TIMEOUT': 0 # Faking cache pruned too frequently
}}

with override_settings(CACHES=foo_cache, ST_RATELIMIT_CACHE='foo'):
with warnings.catch_warnings(record=True): # Ignore warnings
caches['foo'].clear()
self.assertFalse(one(req))
self.assertFalse(one(req))

Expand All @@ -246,11 +251,16 @@ def one(_):
pass

foo_cache = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
},
'foo': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'foo'}}

with override_settings(CACHES=foo_cache, ST_RATELIMIT_CACHE='foo'):
with warnings.catch_warnings(record=True) as w:
utils.cache_clear()
one(req)
self.assertEqual(len(w), 1)
self.assertEqual(
Expand All @@ -263,11 +273,11 @@ def one(_):
'settings.ST_RATELIMIT_SKIP_TIMEOUT_CHECK to True. '
'This will raise an exception in next version.')

utils.cache_clear()
foo_cache['foo']['TIMEOUT'] = None

with override_settings(CACHES=foo_cache, ST_RATELIMIT_CACHE='foo'):
with warnings.catch_warnings(record=True) as w:
caches['foo'].clear()
one(req)
self.assertEqual(len(w), 0)

Expand Down

0 comments on commit 0d1c373

Please sign in to comment.