diff options
| author | Tim Graham <timograham@gmail.com> | 2013-07-13 18:09:24 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-07-13 18:09:24 -0400 |
| commit | 8904e9fb98eaa94fd38e28706e2fe6786d3adc70 (patch) | |
| tree | 34d04fd8d62e02e0858fb6c9cd0a49abe646ceac | |
| parent | 61c8c1b6dcd267a7d4777ff3b0a78eaedb9b95d3 (diff) | |
[1.5.x] Fixed #20681 -- Prevented teardown_databases from attempting to tear down aliases
Thanks simonpercivall.
Backport of d9c580306c from master
| -rw-r--r-- | django/test/simple.py | 4 | ||||
| -rw-r--r-- | tests/regressiontests/test_runner/tests.py | 34 |
2 files changed, 37 insertions, 1 deletions
diff --git a/django/test/simple.py b/django/test/simple.py index e062f5e1e8..24471ca76e 100644 --- a/django/test/simple.py +++ b/django/test/simple.py @@ -310,12 +310,14 @@ class DjangoTestSuiteRunner(object): for alias in aliases: connection = connections[alias] - old_names.append((connection, db_name, True)) if test_db_name is None: test_db_name = connection.creation.create_test_db( self.verbosity, autoclobber=not self.interactive) + destroy = True else: connection.settings_dict['NAME'] = test_db_name + destroy = False + old_names.append((connection, db_name, destroy)) for alias, mirror_alias in mirrored_aliases.items(): mirrors.append((alias, connections[alias].settings_dict['NAME'])) diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py index 48a8e09978..5c51ad5aa5 100644 --- a/tests/regressiontests/test_runner/tests.py +++ b/tests/regressiontests/test_runner/tests.py @@ -310,6 +310,40 @@ class AliasedDefaultTestSetupTest(unittest.TestCase): db.connections = old_db_connections +class AliasedDatabaseTest(unittest.TestCase): + def test_setup_aliased_databases(self): + from django.db.backends.dummy.base import DatabaseCreation + + runner = DjangoTestSuiteRunner(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.setup_databases() + runner.teardown_databases(old_config) + + self.assertEquals(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): |
