mirror of
https://github.com/django/django.git
synced 2025-01-24 00:59:20 +00:00
Fixed #15029 -- Moved to database backends the ability to decide if two DATABASES items are different when creating temporary databases for tests.
hG: Enter commit message. Lines beginning with 'HG:' are removed. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15392 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
77030ccc1e
commit
dc5f2607de
@ -476,3 +476,17 @@ class BaseDatabaseCreation(object):
|
|||||||
def sql_table_creation_suffix(self):
|
def sql_table_creation_suffix(self):
|
||||||
"SQL to append to the end of the test table creation statements"
|
"SQL to append to the end of the test table creation statements"
|
||||||
return ''
|
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']
|
||||||
|
)
|
||||||
|
@ -259,3 +259,13 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||||||
names as handled by Django haven't real counterparts in Oracle.
|
names as handled by Django haven't real counterparts in Oracle.
|
||||||
"""
|
"""
|
||||||
return self.connection.settings_dict['NAME']
|
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'],
|
||||||
|
)
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
import sys
|
|
||||||
import signal
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.db.models import get_app, get_apps
|
from django.db.models import get_app, get_apps
|
||||||
@ -203,7 +200,7 @@ def dependency_ordered(test_databases, dependencies):
|
|||||||
deferred = []
|
deferred = []
|
||||||
|
|
||||||
while test_databases:
|
while test_databases:
|
||||||
signature, aliases = test_databases.pop()
|
signature, (db_name, aliases) = test_databases.pop()
|
||||||
dependencies_satisfied = True
|
dependencies_satisfied = True
|
||||||
for alias in aliases:
|
for alias in aliases:
|
||||||
if alias in dependencies:
|
if alias in dependencies:
|
||||||
@ -217,10 +214,10 @@ def dependency_ordered(test_databases, dependencies):
|
|||||||
resolved_databases.add(alias)
|
resolved_databases.add(alias)
|
||||||
|
|
||||||
if dependencies_satisfied:
|
if dependencies_satisfied:
|
||||||
ordered_test_databases.append((signature, aliases))
|
ordered_test_databases.append((signature, (db_name, aliases)))
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
deferred.append((signature, aliases))
|
deferred.append((signature, (db_name, aliases)))
|
||||||
|
|
||||||
if not changed:
|
if not changed:
|
||||||
raise ImproperlyConfigured("Circular dependency in TEST_DEPENDENCIES")
|
raise ImproperlyConfigured("Circular dependency in TEST_DEPENDENCIES")
|
||||||
@ -276,12 +273,11 @@ class DjangoTestSuiteRunner(object):
|
|||||||
# Store a tuple with DB parameters that uniquely identify it.
|
# Store a tuple with DB parameters that uniquely identify it.
|
||||||
# If we have two aliases with the same values for that tuple,
|
# If we have two aliases with the same values for that tuple,
|
||||||
# we only need to create the test database once.
|
# we only need to create the test database once.
|
||||||
test_databases.setdefault((
|
item = test_databases.setdefault(
|
||||||
connection.settings_dict['HOST'],
|
connection.creation.test_db_signature(),
|
||||||
connection.settings_dict['PORT'],
|
(connection.settings_dict['NAME'], [])
|
||||||
connection.settings_dict['ENGINE'],
|
)
|
||||||
connection.settings_dict['NAME'],
|
item[1].append(alias)
|
||||||
), []).append(alias)
|
|
||||||
|
|
||||||
if 'TEST_DEPENDENCIES' in connection.settings_dict:
|
if 'TEST_DEPENDENCIES' in connection.settings_dict:
|
||||||
dependencies[alias] = connection.settings_dict['TEST_DEPENDENCIES']
|
dependencies[alias] = connection.settings_dict['TEST_DEPENDENCIES']
|
||||||
@ -292,7 +288,7 @@ class DjangoTestSuiteRunner(object):
|
|||||||
# Second pass -- actually create the databases.
|
# Second pass -- actually create the databases.
|
||||||
old_names = []
|
old_names = []
|
||||||
mirrors = []
|
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
|
# Actually create the database for the first connection
|
||||||
connection = connections[aliases[0]]
|
connection = connections[aliases[0]]
|
||||||
old_names.append((connection, db_name, True))
|
old_names.append((connection, db_name, True))
|
||||||
|
@ -33,9 +33,9 @@ class DependencyOrderingTests(unittest.TestCase):
|
|||||||
|
|
||||||
def test_simple_dependencies(self):
|
def test_simple_dependencies(self):
|
||||||
raw = [
|
raw = [
|
||||||
('s1', ['alpha']),
|
('s1', ('s1_db', ['alpha'])),
|
||||||
('s2', ['bravo']),
|
('s2', ('s2_db', ['bravo'])),
|
||||||
('s3', ['charlie']),
|
('s3', ('s3_db', ['charlie'])),
|
||||||
]
|
]
|
||||||
dependencies = {
|
dependencies = {
|
||||||
'alpha': ['charlie'],
|
'alpha': ['charlie'],
|
||||||
@ -43,7 +43,7 @@ class DependencyOrderingTests(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
ordered = simple.dependency_ordered(raw, dependencies=dependencies)
|
ordered = simple.dependency_ordered(raw, dependencies=dependencies)
|
||||||
ordered_sigs = [sig for sig,aliases in ordered]
|
ordered_sigs = [sig for sig,value in ordered]
|
||||||
|
|
||||||
self.assertIn('s1', ordered_sigs)
|
self.assertIn('s1', ordered_sigs)
|
||||||
self.assertIn('s2', ordered_sigs)
|
self.assertIn('s2', ordered_sigs)
|
||||||
@ -53,9 +53,9 @@ class DependencyOrderingTests(unittest.TestCase):
|
|||||||
|
|
||||||
def test_chained_dependencies(self):
|
def test_chained_dependencies(self):
|
||||||
raw = [
|
raw = [
|
||||||
('s1', ['alpha']),
|
('s1', ('s1_db', ['alpha'])),
|
||||||
('s2', ['bravo']),
|
('s2', ('s2_db', ['bravo'])),
|
||||||
('s3', ['charlie']),
|
('s3', ('s3_db', ['charlie'])),
|
||||||
]
|
]
|
||||||
dependencies = {
|
dependencies = {
|
||||||
'alpha': ['bravo'],
|
'alpha': ['bravo'],
|
||||||
@ -63,7 +63,7 @@ class DependencyOrderingTests(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
ordered = simple.dependency_ordered(raw, dependencies=dependencies)
|
ordered = simple.dependency_ordered(raw, dependencies=dependencies)
|
||||||
ordered_sigs = [sig for sig,aliases in ordered]
|
ordered_sigs = [sig for sig,value in ordered]
|
||||||
|
|
||||||
self.assertIn('s1', ordered_sigs)
|
self.assertIn('s1', ordered_sigs)
|
||||||
self.assertIn('s2', ordered_sigs)
|
self.assertIn('s2', ordered_sigs)
|
||||||
@ -78,10 +78,10 @@ class DependencyOrderingTests(unittest.TestCase):
|
|||||||
|
|
||||||
def test_multiple_dependencies(self):
|
def test_multiple_dependencies(self):
|
||||||
raw = [
|
raw = [
|
||||||
('s1', ['alpha']),
|
('s1', ('s1_db', ['alpha'])),
|
||||||
('s2', ['bravo']),
|
('s2', ('s2_db', ['bravo'])),
|
||||||
('s3', ['charlie']),
|
('s3', ('s3_db', ['charlie'])),
|
||||||
('s4', ['delta']),
|
('s4', ('s4_db', ['delta'])),
|
||||||
]
|
]
|
||||||
dependencies = {
|
dependencies = {
|
||||||
'alpha': ['bravo','delta'],
|
'alpha': ['bravo','delta'],
|
||||||
@ -108,8 +108,8 @@ class DependencyOrderingTests(unittest.TestCase):
|
|||||||
|
|
||||||
def test_circular_dependencies(self):
|
def test_circular_dependencies(self):
|
||||||
raw = [
|
raw = [
|
||||||
('s1', ['alpha']),
|
('s1', ('s1_db', ['alpha'])),
|
||||||
('s2', ['bravo']),
|
('s2', ('s2_db', ['bravo'])),
|
||||||
]
|
]
|
||||||
dependencies = {
|
dependencies = {
|
||||||
'bravo': ['alpha'],
|
'bravo': ['alpha'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user