Made cache table test case multidb capable. Refs #16411. Thanks, Russ.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16513 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
2b2bec0cc9
commit
b884990388
|
@ -14,10 +14,10 @@ from django.conf import settings
|
||||||
from django.core import management
|
from django.core import management
|
||||||
from django.core.cache import get_cache, DEFAULT_CACHE_ALIAS
|
from django.core.cache import get_cache, DEFAULT_CACHE_ALIAS
|
||||||
from django.core.cache.backends.base import CacheKeyWarning, InvalidCacheBackendError
|
from django.core.cache.backends.base import CacheKeyWarning, InvalidCacheBackendError
|
||||||
from django.db import connections, router
|
from django.db import router
|
||||||
from django.http import HttpResponse, HttpRequest, QueryDict
|
from django.http import HttpResponse, HttpRequest, QueryDict
|
||||||
from django.middleware.cache import FetchFromCacheMiddleware, UpdateCacheMiddleware, CacheMiddleware
|
from django.middleware.cache import FetchFromCacheMiddleware, UpdateCacheMiddleware, CacheMiddleware
|
||||||
from django.test import RequestFactory
|
from django.test import RequestFactory, TestCase
|
||||||
from django.test.utils import get_warnings_state, restore_warnings_state, override_settings
|
from django.test.utils import get_warnings_state, restore_warnings_state, override_settings
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
@ -771,29 +771,32 @@ class DBCacheRouter(object):
|
||||||
return 'other'
|
return 'other'
|
||||||
|
|
||||||
def allow_syncdb(self, db, model):
|
def allow_syncdb(self, db, model):
|
||||||
|
print self, db, model
|
||||||
if model._meta.app_label == 'django_cache':
|
if model._meta.app_label == 'django_cache':
|
||||||
return db == 'other'
|
return db == 'other'
|
||||||
|
|
||||||
class CreateCacheTableForDBCacheTests(unittest.TestCase):
|
|
||||||
|
class CreateCacheTableForDBCacheTests(TestCase):
|
||||||
|
multi_db = True
|
||||||
|
|
||||||
def test_createcachetable_observes_database_router(self):
|
def test_createcachetable_observes_database_router(self):
|
||||||
with override_settings(DEBUG=True):
|
|
||||||
old_routers = router.routers
|
old_routers = router.routers
|
||||||
try:
|
try:
|
||||||
router.routers = [DBCacheRouter()]
|
router.routers = [DBCacheRouter()]
|
||||||
# cache table should not be created on 'default'
|
# cache table should not be created on 'default'
|
||||||
|
with self.assertNumQueries(0):
|
||||||
management.call_command('createcachetable', 'cache_table',
|
management.call_command('createcachetable', 'cache_table',
|
||||||
database='default',
|
database='default',
|
||||||
verbosity=0, interactive=False)
|
verbosity=0, interactive=False)
|
||||||
self.assertEqual(len(connections['default'].queries), 0)
|
|
||||||
# cache table should be created on 'other'
|
# cache table should be created on 'other'
|
||||||
|
with self.assertNumQueries(1):
|
||||||
management.call_command('createcachetable', 'cache_table',
|
management.call_command('createcachetable', 'cache_table',
|
||||||
database='other',
|
database='other',
|
||||||
verbosity=0, interactive=False)
|
verbosity=0, interactive=False)
|
||||||
self.assertNotEqual(len(connections['other'].queries), 0)
|
|
||||||
finally:
|
finally:
|
||||||
router.routers = old_routers
|
router.routers = old_routers
|
||||||
|
|
||||||
|
|
||||||
class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
|
class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
|
||||||
backend_name = 'django.core.cache.backends.locmem.LocMemCache'
|
backend_name = 'django.core.cache.backends.locmem.LocMemCache'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue