Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit b884990388245c5a5a5d8ba2ff3220515c3b54a5 1 parent 2b2bec0
@jezdez jezdez authored
Showing with 16 additions and 13 deletions.
  1. +16 −13 tests/regressiontests/cache/tests.py
View
29 tests/regressiontests/cache/tests.py
@@ -14,10 +14,10 @@
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 @@ def db_for_write(self, model, **hints):
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'
Please sign in to comment.
Something went wrong with that request. Please try again.