Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.5.x] Fixed #20681 -- Prevented teardown_databases from attempting …

…to tear down aliases

Thanks simonpercivall.

Backport of d9c5803 from master
  • Loading branch information...
commit 8904e9fb98eaa94fd38e28706e2fe6786d3adc70 1 parent 61c8c1b
Tim Graham authored July 13, 2013
4  django/test/simple.py
@@ -310,12 +310,14 @@ def setup_databases(self, **kwargs):
310 310
 
311 311
             for alias in aliases:
312 312
                 connection = connections[alias]
313  
-                old_names.append((connection, db_name, True))
314 313
                 if test_db_name is None:
315 314
                     test_db_name = connection.creation.create_test_db(
316 315
                             self.verbosity, autoclobber=not self.interactive)
  316
+                    destroy = True
317 317
                 else:
318 318
                     connection.settings_dict['NAME'] = test_db_name
  319
+                    destroy = False
  320
+                old_names.append((connection, db_name, destroy))
319 321
 
320 322
         for alias, mirror_alias in mirrored_aliases.items():
321 323
             mirrors.append((alias, connections[alias].settings_dict['NAME']))
34  tests/regressiontests/test_runner/tests.py
@@ -310,6 +310,40 @@ def test_setup_aliased_default_database(self):
310 310
             db.connections = old_db_connections
311 311
 
312 312
 
  313
+class AliasedDatabaseTest(unittest.TestCase):
  314
+    def test_setup_aliased_databases(self):
  315
+        from django.db.backends.dummy.base import DatabaseCreation
  316
+
  317
+        runner = DjangoTestSuiteRunner(verbosity=0)
  318
+        old_db_connections = db.connections
  319
+        old_destroy_test_db = DatabaseCreation.destroy_test_db
  320
+        old_create_test_db = DatabaseCreation.create_test_db
  321
+        try:
  322
+            destroyed_names = []
  323
+            DatabaseCreation.destroy_test_db = lambda self, old_database_name, verbosity=1: destroyed_names.append(old_database_name)
  324
+            DatabaseCreation.create_test_db = lambda self, verbosity=1, autoclobber=False: self._get_test_db_name()
  325
+
  326
+            db.connections = db.ConnectionHandler({
  327
+                'default': {
  328
+                    'ENGINE': 'django.db.backends.dummy',
  329
+                    'NAME': 'dbname',
  330
+                },
  331
+                'other': {
  332
+                    'ENGINE': 'django.db.backends.dummy',
  333
+                    'NAME': 'dbname',
  334
+                }
  335
+            })
  336
+
  337
+            old_config = runner.setup_databases()
  338
+            runner.teardown_databases(old_config)
  339
+
  340
+            self.assertEquals(destroyed_names.count('dbname'), 1)
  341
+        finally:
  342
+            DatabaseCreation.create_test_db = old_create_test_db
  343
+            DatabaseCreation.destroy_test_db = old_destroy_test_db
  344
+            db.connections = old_db_connections
  345
+
  346
+
313 347
 class DeprecationDisplayTest(AdminScriptTestCase):
314 348
     # tests for 19546
315 349
     def setUp(self):

0 notes on commit 8904e9f

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