Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…to tear down aliases

Thanks simonpercivall.

Backport of d9c5803 from master
  • Loading branch information...
commit e5241902f3d4b0f925eb67809dfb732dd46ba597 1 parent 26b88e7
@timgraham timgraham authored
Showing with 37 additions and 2 deletions.
  1. +3 −2 django/test/runner.py
  2. +34 −0 tests/test_runner/tests.py
View
5 django/test/runner.py
@@ -272,15 +272,16 @@ def setup_databases(verbosity, interactive, **kwargs):
test_databases.items(), dependencies):
test_db_name = None
# Actually create the database for the first connection
-
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(
verbosity, autoclobber=not 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']))
View
34 tests/test_runner/tests.py
@@ -315,6 +315,40 @@ def test_setup_aliased_default_database(self):
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):
Please sign in to comment.
Something went wrong with that request. Please try again.