diff options
author | Ramiro Morales <cramm0@gmail.com> | 2011-02-02 15:33:37 +0000 |
---|---|---|
committer | Ramiro Morales <cramm0@gmail.com> | 2011-02-02 15:33:37 +0000 |
commit | 0b8b9fbe306acd1ae310fe292fabec493f329a05 (patch) | |
tree | a74b16c01928437f376b72d32a2d9c499e90e20f | |
parent | 837a2e2773125fcda0c419597b2c19a3d05b4879 (diff) | |
download | django-0b8b9fbe306acd1ae310fe292fabec493f329a05.tar.gz |
[1.2.X] Fixed #15029 -- Moved to database backends the ability to decide if two DATABASES items are different when creating temporary databases for tests.
Backport of [15392] from trunk
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15395 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r-- | django/db/backends/creation.py | 14 | ||||
-rw-r--r-- | django/db/backends/oracle/creation.py | 10 | ||||
-rw-r--r-- | django/test/simple.py | 29 | ||||
-rw-r--r-- | tests/regressiontests/test_runner/tests.py | 29 |
4 files changed, 52 insertions, 30 deletions
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py index a5217f1175..7da44f8c32 100644 --- a/django/db/backends/creation.py +++ b/django/db/backends/creation.py @@ -468,3 +468,17 @@ class BaseDatabaseCreation(object): def sql_table_creation_suffix(self): "SQL to append to the end of the test table creation statements" return '' + + def test_db_signature(self): + """ + Returns a tuple with elements of self.connection.settings_dict (a + DATABASES setting value) that uniquely identify a database + accordingly to the RDBMS particularities. + """ + settings_dict = self.connection.settings_dict + return ( + settings_dict['HOST'], + settings_dict['PORT'], + settings_dict['ENGINE'], + settings_dict['NAME'] + ) diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py index 940af15d06..fd02ca07ba 100644 --- a/django/db/backends/oracle/creation.py +++ b/django/db/backends/oracle/creation.py @@ -114,6 +114,16 @@ class DatabaseCreation(BaseDatabaseCreation): return self.connection.settings_dict['NAME'] + def test_db_signature(self): + settings_dict = self.connection.settings_dict + return ( + settings_dict['HOST'], + settings_dict['PORT'], + settings_dict['ENGINE'], + settings_dict['NAME'], + settings_dict['TEST_USER'], + ) + def _destroy_test_db(self, test_database_name, verbosity=1): """ Destroy a test database, prompting the user for confirmation if the diff --git a/django/test/simple.py b/django/test/simple.py index 8f08fd0692..7d9332ef57 100644 --- a/django/test/simple.py +++ b/django/test/simple.py @@ -240,7 +240,7 @@ def dependency_ordered(test_databases, dependencies): deferred = [] while test_databases: - signature, aliases = test_databases.pop() + signature, (db_name, aliases) = test_databases.pop() dependencies_satisfied = True for alias in aliases: if alias in dependencies: @@ -254,10 +254,10 @@ def dependency_ordered(test_databases, dependencies): resolved_databases.add(alias) if dependencies_satisfied: - ordered_test_databases.append((signature, aliases)) + ordered_test_databases.append((signature, (db_name, aliases))) changed = True else: - deferred.append((signature, aliases)) + deferred.append((signature, (db_name, aliases))) if not changed: raise ImproperlyConfigured("Circular dependency in TEST_DEPENDENCIES") @@ -309,26 +309,25 @@ class DjangoTestSuiteRunner(object): # the alias. mirrored_aliases[alias] = connection.settings_dict['TEST_MIRROR'] else: - # Store the (engine, name) pair. If we have two aliases - # with the same pair, we only need to create the test database - # once. - test_databases.setdefault(( - connection.settings_dict['HOST'], - connection.settings_dict['PORT'], - connection.settings_dict['ENGINE'], - connection.settings_dict['NAME'], - ), []).append(alias) + # Store a tuple with DB parameters that uniquely identify it. + # If we have two aliases with the same values for that tuple, + # we only need to create the test database once. + item = test_databases.setdefault( + connection.creation.test_db_signature(), + (connection.settings_dict['NAME'], []) + ) + item[1].append(alias) if 'TEST_DEPENDENCIES' in connection.settings_dict: dependencies[alias] = connection.settings_dict['TEST_DEPENDENCIES'] else: - if alias != 'default': - dependencies[alias] = connection.settings_dict.get('TEST_DEPENDENCIES', ['default']) + if alias != DEFAULT_DB_ALIAS: + dependencies[alias] = connection.settings_dict.get('TEST_DEPENDENCIES', [DEFAULT_DB_ALIAS]) # Second pass -- actually create the databases. old_names = [] mirrors = [] - for (host, port, engine, db_name), aliases in dependency_ordered(test_databases.items(), dependencies): + for signature, (db_name, aliases) in dependency_ordered(test_databases.items(), dependencies): # Actually create the database for the first connection connection = connections[aliases[0]] old_names.append((connection, db_name, True)) diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py index 3387d659df..203ed1ebd3 100644 --- a/tests/regressiontests/test_runner/tests.py +++ b/tests/regressiontests/test_runner/tests.py @@ -3,7 +3,6 @@ Tests for django test runner """ import StringIO import unittest -import django from django.core.exceptions import ImproperlyConfigured from django.test import simple @@ -33,9 +32,9 @@ class DependencyOrderingTests(unittest.TestCase): def test_simple_dependencies(self): raw = [ - ('s1', ['alpha']), - ('s2', ['bravo']), - ('s3', ['charlie']), + ('s1', ('s1_db', ['alpha'])), + ('s2', ('s2_db', ['bravo'])), + ('s3', ('s3_db', ['charlie'])), ] dependencies = { 'alpha': ['charlie'], @@ -43,7 +42,7 @@ class DependencyOrderingTests(unittest.TestCase): } ordered = simple.dependency_ordered(raw, dependencies=dependencies) - ordered_sigs = [sig for sig,aliases in ordered] + ordered_sigs = [sig for sig,value in ordered] self.assertTrue('s1' in ordered_sigs) self.assertTrue('s2' in ordered_sigs) @@ -53,9 +52,9 @@ class DependencyOrderingTests(unittest.TestCase): def test_chained_dependencies(self): raw = [ - ('s1', ['alpha']), - ('s2', ['bravo']), - ('s3', ['charlie']), + ('s1', ('s1_db', ['alpha'])), + ('s2', ('s2_db', ['bravo'])), + ('s3', ('s3_db', ['charlie'])), ] dependencies = { 'alpha': ['bravo'], @@ -63,7 +62,7 @@ class DependencyOrderingTests(unittest.TestCase): } ordered = simple.dependency_ordered(raw, dependencies=dependencies) - ordered_sigs = [sig for sig,aliases in ordered] + ordered_sigs = [sig for sig,value in ordered] self.assertTrue('s1' in ordered_sigs) self.assertTrue('s2' in ordered_sigs) @@ -78,10 +77,10 @@ class DependencyOrderingTests(unittest.TestCase): def test_multiple_dependencies(self): raw = [ - ('s1', ['alpha']), - ('s2', ['bravo']), - ('s3', ['charlie']), - ('s4', ['delta']), + ('s1', ('s1_db', ['alpha'])), + ('s2', ('s2_db', ['bravo'])), + ('s3', ('s3_db', ['charlie'])), + ('s4', ('s4_db', ['delta'])), ] dependencies = { 'alpha': ['bravo','delta'], @@ -108,8 +107,8 @@ class DependencyOrderingTests(unittest.TestCase): def test_circular_dependencies(self): raw = [ - ('s1', ['alpha']), - ('s2', ['bravo']), + ('s1', ('s1_db', ['alpha'])), + ('s2', ('s2_db', ['bravo'])), ] dependencies = { 'bravo': ['alpha'], |