-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests.py
52 lines (40 loc) · 1.42 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from django.test import TestCase
def _get_cache(backend):
try:
# 1.9+
from django.core.cache import caches
except ImportError:
# <1.9
from django.core.cache import get_cache
return get_cache(backend)
return caches[backend]
class BaseCacheTestCase(TestCase):
def setUp(self):
self.cache = _get_cache(self.cache_name)
def key(self, key):
return u'ft-cache-test:{cache}:{key}'.format(key=key,
cache=self.cache_name)
class WorkingCacheTests(BaseCacheTestCase):
cache_name = 'default'
def test_basics(self):
"""Sanity check that things still work as expected"""
key = self.key('basics')
val = 'value'
self.cache.delete(key)
self.cache.set(key, val)
self.assertEqual(self.cache.get(key), val)
def test_overflow(self):
"""Inserting past 1MB limit should not raise error"""
key = self.key('big')
blob = '0' * 1048576
self.cache.set(key, blob)
self.assertEqual(self.cache.get(key), None)
class BadCacheTests(BaseCacheTestCase):
cache_name = 'faulty'
def test_basics(self):
"""Cache should fail, log traceback, but not raise error"""
key = self.key('basics')
val = 'value'
self.cache.delete(key)
self.cache.set(key, val)
self.assertEqual(self.cache.get(key), None)