diff options
| author | Tim Graham <timograham@gmail.com> | 2013-07-13 17:46:05 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-07-13 17:46:37 -0400 |
| commit | e5241902f3d4b0f925eb67809dfb732dd46ba597 (patch) | |
| tree | e9fec452e3a81f11e268ccd04b62be66d8fa9427 /tests/test_runner | |
| parent | 26b88e7658e7be52de3c72b76ec64b3ce92ceda0 (diff) | |
[1.6.x] Fixed #20681 -- Prevented teardown_databases from attempting to tear down aliases
Thanks simonpercivall.
Backport of d9c580306c from master
Diffstat (limited to 'tests/test_runner')
| -rw-r--r-- | tests/test_runner/tests.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index b13d0e76fc..8b3d99f6d4 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -315,6 +315,40 @@ class AliasedDefaultTestSetupTest(unittest.TestCase): db.connections = old_db_connections +class AliasedDatabaseTeardownTest(unittest.TestCase): + def test_setup_aliased_databases(self): + from django.db.backends.dummy.base import DatabaseCreation + + runner_instance = runner.DiscoverRunner(verbosity=0) + old_db_connections = db.connections + old_destroy_test_db = DatabaseCreation.destroy_test_db + old_create_test_db = DatabaseCreation.create_test_db + try: + destroyed_names = [] + DatabaseCreation.destroy_test_db = lambda self, old_database_name, verbosity=1: destroyed_names.append(old_database_name) + DatabaseCreation.create_test_db = lambda self, verbosity=1, autoclobber=False: self._get_test_db_name() + + db.connections = db.ConnectionHandler({ + 'default': { + 'ENGINE': 'django.db.backends.dummy', + 'NAME': 'dbname', + }, + 'other': { + 'ENGINE': 'django.db.backends.dummy', + 'NAME': 'dbname', + } + }) + + old_config = runner_instance.setup_databases() + runner_instance.teardown_databases(old_config) + + self.assertEqual(destroyed_names.count('dbname'), 1) + finally: + DatabaseCreation.create_test_db = old_create_test_db + DatabaseCreation.destroy_test_db = old_destroy_test_db + db.connections = old_db_connections + + class DeprecationDisplayTest(AdminScriptTestCase): # tests for 19546 def setUp(self): |
