mirror of
https://github.com/Hopiu/django-cachalot.git
synced 2026-05-27 21:33:59 +00:00
Adds a test for CACHALOT_CACHE.
This commit is contained in:
parent
c4ed66b710
commit
5888560850
2 changed files with 25 additions and 3 deletions
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
try:
|
||||
from unittest import skip
|
||||
from unittest import skip, skipIf
|
||||
except ImportError: # For Python 2.6
|
||||
from unittest2 import skip
|
||||
from unittest2 import skip, skipIf
|
||||
import datetime
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User, Permission, Group
|
||||
|
|
@ -1178,3 +1178,22 @@ class AtomicTestCase(TestCase):
|
|||
pass
|
||||
data3 = list(Test.objects.all())
|
||||
self.assertListEqual(data3, [t1])
|
||||
|
||||
|
||||
class SettingsTestCase(TestCase):
|
||||
@skipIf(len(settings.CACHES) == 1,
|
||||
'We can’t change the cache used since there’s only one configured')
|
||||
def test_cache(self):
|
||||
with self.settings(CACHALOT_CACHE='default'):
|
||||
with self.assertNumQueries(1):
|
||||
list(Test.objects.all())
|
||||
with self.assertNumQueries(0):
|
||||
list(Test.objects.all())
|
||||
|
||||
other_cache = [k for k in settings.CACHES if k != 'default'][0]
|
||||
|
||||
with self.settings(CACHALOT_CACHE=other_cache):
|
||||
with self.assertNumQueries(1):
|
||||
list(Test.objects.all())
|
||||
with self.assertNumQueries(0):
|
||||
list(Test.objects.all())
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ CACHES = {
|
|||
'LOCATION': '127.0.0.1:6379:0',
|
||||
}
|
||||
}
|
||||
DEFAULT_CACHE_KEY = os.environ.get('CACHE_BACKEND', 'locmem')
|
||||
CACHES['default'] = CACHES[DEFAULT_CACHE_KEY]
|
||||
del CACHES[DEFAULT_CACHE_KEY]
|
||||
|
||||
settings.configure(
|
||||
DEBUG=True,
|
||||
|
|
@ -46,7 +49,7 @@ settings.configure(
|
|||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
),
|
||||
CACHES={'default': CACHES[os.environ.get('CACHE_BACKEND', 'locmem')]},
|
||||
CACHES=CACHES,
|
||||
MIDDLEWARE_CLASSES=(),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue