Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Jannis Leidel authored July 05, 2011

Showing 1 changed file with 16 additions and 13 deletions. Show diff stats Hide diff stats

  1. 29  tests/regressiontests/cache/tests.py
29  tests/regressiontests/cache/tests.py
@@ -14,10 +14,10 @@
14 14
 from django.core import management
15 15
 from django.core.cache import get_cache, DEFAULT_CACHE_ALIAS
16 16
 from django.core.cache.backends.base import CacheKeyWarning, InvalidCacheBackendError
17  
-from django.db import connections, router
  17
+from django.db import router
18 18
 from django.http import HttpResponse, HttpRequest, QueryDict
19 19
 from django.middleware.cache import FetchFromCacheMiddleware, UpdateCacheMiddleware, CacheMiddleware
20  
-from django.test import RequestFactory
  20
+from django.test import RequestFactory, TestCase
21 21
 from django.test.utils import get_warnings_state, restore_warnings_state, override_settings
22 22
 from django.utils import translation
23 23
 from django.utils import unittest
@@ -771,28 +771,31 @@ def db_for_write(self, model, **hints):
771 771
             return 'other'
772 772
 
773 773
     def allow_syncdb(self, db, model):
  774
+        print self, db, model
774 775
         if model._meta.app_label == 'django_cache':
775 776
             return db == 'other'
776 777
 
777  
-class CreateCacheTableForDBCacheTests(unittest.TestCase):
  778
+
  779
+class CreateCacheTableForDBCacheTests(TestCase):
  780
+    multi_db = True
778 781
 
779 782
     def test_createcachetable_observes_database_router(self):
780  
-        with override_settings(DEBUG=True):
781  
-            old_routers = router.routers
782  
-            try:
783  
-                router.routers = [DBCacheRouter()]
784  
-                # cache table should not be created on 'default'
  783
+        old_routers = router.routers
  784
+        try:
  785
+            router.routers = [DBCacheRouter()]
  786
+            # cache table should not be created on 'default'
  787
+            with self.assertNumQueries(0):
785 788
                 management.call_command('createcachetable', 'cache_table',
786 789
                                         database='default',
787 790
                                         verbosity=0, interactive=False)
788  
-                self.assertEqual(len(connections['default'].queries), 0)
789  
-                # cache table should be created on 'other'
  791
+            # cache table should be created on 'other'
  792
+            with self.assertNumQueries(1):
790 793
                 management.call_command('createcachetable', 'cache_table',
791 794
                                         database='other',
792 795
                                         verbosity=0, interactive=False)
793  
-                self.assertNotEqual(len(connections['other'].queries), 0)
794  
-            finally:
795  
-                router.routers = old_routers
  796
+        finally:
  797
+            router.routers = old_routers
  798
+
796 799
 
797 800
 class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
798 801
     backend_name = 'django.core.cache.backends.locmem.LocMemCache'

0 notes on commit b884990

Please sign in to comment.
Something went wrong with that request. Please try again.