Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20681 -- Prevented teardown_databases from attempting to tear …

…down aliases

Thanks simonpercivall.
  • Loading branch information...
commit d9c580306c4b7da49d7fd2fd1ea0e6333a784113 1 parent 1b142ef
Tim Graham authored July 13, 2013
5  django/test/runner.py
@@ -272,15 +272,16 @@ def setup_databases(verbosity, interactive, **kwargs):
272 272
         test_databases.items(), dependencies):
273 273
         test_db_name = None
274 274
         # Actually create the database for the first connection
275  
-
276 275
         for alias in aliases:
277 276
             connection = connections[alias]
278  
-            old_names.append((connection, db_name, True))
279 277
             if test_db_name is None:
280 278
                 test_db_name = connection.creation.create_test_db(
281 279
                         verbosity, autoclobber=not interactive)
  280
+                destroy = True
282 281
             else:
283 282
                 connection.settings_dict['NAME'] = test_db_name
  283
+                destroy = False
  284
+            old_names.append((connection, db_name, destroy))
284 285
 
285 286
     for alias, mirror_alias in mirrored_aliases.items():
286 287
         mirrors.append((alias, connections[alias].settings_dict['NAME']))
34  tests/test_runner/tests.py
@@ -316,6 +316,40 @@ def test_setup_aliased_default_database(self):
316 316
             db.connections = old_db_connections
317 317
 
318 318
 
  319
+class AliasedDatabaseTeardownTest(unittest.TestCase):
  320
+    def test_setup_aliased_databases(self):
  321
+        from django.db.backends.dummy.base import DatabaseCreation
  322
+
  323
+        runner_instance = runner.DiscoverRunner(verbosity=0)
  324
+        old_db_connections = db.connections
  325
+        old_destroy_test_db = DatabaseCreation.destroy_test_db
  326
+        old_create_test_db = DatabaseCreation.create_test_db
  327
+        try:
  328
+            destroyed_names = []
  329
+            DatabaseCreation.destroy_test_db = lambda self, old_database_name, verbosity=1: destroyed_names.append(old_database_name)
  330
+            DatabaseCreation.create_test_db = lambda self, verbosity=1, autoclobber=False: self._get_test_db_name()
  331
+
  332
+            db.connections = db.ConnectionHandler({
  333
+                'default': {
  334
+                    'ENGINE': 'django.db.backends.dummy',
  335
+                    'NAME': 'dbname',
  336
+                },
  337
+                'other': {
  338
+                    'ENGINE': 'django.db.backends.dummy',
  339
+                    'NAME': 'dbname',
  340
+                }
  341
+            })
  342
+
  343
+            old_config = runner_instance.setup_databases()
  344
+            runner_instance.teardown_databases(old_config)
  345
+
  346
+            self.assertEqual(destroyed_names.count('dbname'), 1)
  347
+        finally:
  348
+            DatabaseCreation.create_test_db = old_create_test_db
  349
+            DatabaseCreation.destroy_test_db = old_destroy_test_db
  350
+            db.connections = old_db_connections
  351
+
  352
+
319 353
 class DeprecationDisplayTest(AdminScriptTestCase):
320 354
     # tests for 19546
321 355
     def setUp(self):

0 notes on commit d9c5803

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