From 2cbd579efe2d646814bd6cb7aca8bd43a96f14ae Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 4 Jul 2013 19:58:58 -0400 Subject: [PATCH] Fixed #19940 -- Made test.runner.setup_databases properly handle aliases for default db. Thanks simonpercivall. --- django/test/runner.py | 3 ++- tests/test_runner/tests.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/django/test/runner.py b/django/test/runner.py index 709b685de5d..98113e9b67c 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -238,6 +238,7 @@ def setup_databases(verbosity, interactive, **kwargs): mirrored_aliases = {} test_databases = {} dependencies = {} + default_sig = connections[DEFAULT_DB_ALIAS].creation.test_db_signature() for alias in connections: connection = connections[alias] if connection.settings_dict['TEST_MIRROR']: @@ -259,7 +260,7 @@ def setup_databases(verbosity, interactive, **kwargs): dependencies[alias] = ( connection.settings_dict['TEST_DEPENDENCIES']) else: - if alias != DEFAULT_DB_ALIAS: + if alias != DEFAULT_DB_ALIAS and connection.creation.test_db_signature() != default_sig: dependencies[alias] = connection.settings_dict.get( 'TEST_DEPENDENCIES', [DEFAULT_DB_ALIAS]) diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index 4e9e44bc125..0c7c966498d 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -291,6 +291,31 @@ class DummyBackendTest(unittest.TestCase): db.connections = old_db_connections +class AliasedDefaultTestSetupTest(unittest.TestCase): + def test_setup_aliased_default_database(self): + """ + Test that setup_datebases() doesn't fail when 'default' is aliased + """ + runner_instance = runner.DiscoverRunner(verbosity=0) + old_db_connections = db.connections + try: + db.connections = db.ConnectionHandler({ + 'default': { + 'NAME': 'dummy' + }, + 'aliased': { + 'NAME': 'dummy' + } + }) + old_config = runner_instance.setup_databases() + runner_instance.teardown_databases(old_config) + except Exception as e: + self.fail("setup_databases/teardown_databases unexpectedly raised " + "an error: %s" % e) + finally: + db.connections = old_db_connections + + class DeprecationDisplayTest(AdminScriptTestCase): # tests for 19546 def setUp(self):