diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-11-19 19:56:31 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-11-19 19:56:31 +0000 |
| commit | d0eb4693ab479ef0667cd5286ecc89c347b6b2de (patch) | |
| tree | 37719ea2ecb115185430ee3c8afd7cb705691660 /tests | |
| parent | c8c71057aad21d71b512a87cc4a7020e8abfb12f (diff) | |
Fixed #15255 -- Ensured createcachetable honors database routers.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17114 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/cache/tests.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index f1590d1121..5f9676beb6 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -16,6 +16,7 @@ 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 router from django.http import HttpResponse, HttpRequest, QueryDict from django.middleware.cache import (FetchFromCacheMiddleware, UpdateCacheMiddleware, CacheMiddleware) @@ -775,6 +776,44 @@ class DBCacheTests(unittest.TestCase, BaseCacheTests): self.perform_cull_test(50, 18) +class DBCacheRouter(object): + """A router that puts the cache table on the 'other' database.""" + + def db_for_read(self, model, **hints): + if model._meta.app_label == 'django_cache': + return 'other' + + def db_for_write(self, model, **hints): + if model._meta.app_label == 'django_cache': + return 'other' + + def allow_syncdb(self, db, model): + if model._meta.app_label == 'django_cache': + return db == 'other' + + +class CreateCacheTableForDBCacheTests(TestCase): + multi_db = True + + def test_createcachetable_observes_database_router(self): + old_routers = router.routers + try: + router.routers = [DBCacheRouter()] + # cache table should not be created on 'default' + with self.assertNumQueries(0, using='default'): + management.call_command('createcachetable', 'cache_table', + database='default', + verbosity=0, interactive=False) + # cache table should be created on 'other' + # one query is used to create the table and another one the index + with self.assertNumQueries(2, using='other'): + management.call_command('createcachetable', 'cache_table', + database='other', + verbosity=0, interactive=False) + finally: + router.routers = old_routers + + class LocMemCacheTests(unittest.TestCase, BaseCacheTests): backend_name = 'django.core.cache.backends.locmem.LocMemCache' |
