From b884990388245c5a5a5d8ba2ff3220515c3b54a5 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Tue, 5 Jul 2011 13:55:14 +0000 Subject: [PATCH] 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 --- tests/regressiontests/cache/tests.py | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index 278b6b69da..4303ad73e9 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -14,10 +14,10 @@ from django.conf import settings from django.core import management from django.core.cache import get_cache, DEFAULT_CACHE_ALIAS 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.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.utils import translation from django.utils import unittest @@ -771,28 +771,31 @@ class DBCacheRouter(object): return 'other' def allow_syncdb(self, db, model): + print self, db, model if model._meta.app_label == 'django_cache': return db == 'other' -class CreateCacheTableForDBCacheTests(unittest.TestCase): + +class CreateCacheTableForDBCacheTests(TestCase): + multi_db = True def test_createcachetable_observes_database_router(self): - with override_settings(DEBUG=True): - old_routers = router.routers - try: - router.routers = [DBCacheRouter()] - # cache table should not be created on 'default' + old_routers = router.routers + try: + router.routers = [DBCacheRouter()] + # cache table should not be created on 'default' + with self.assertNumQueries(0): management.call_command('createcachetable', 'cache_table', database='default', 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', database='other', verbosity=0, interactive=False) - self.assertNotEqual(len(connections['other'].queries), 0) - finally: - router.routers = old_routers + finally: + router.routers = old_routers + class LocMemCacheTests(unittest.TestCase, BaseCacheTests): backend_name = 'django.core.cache.backends.locmem.LocMemCache'