Code

Ticket #15029: 15029.diff

File 15029.diff, 6.3 KB (added by ramiro, 3 years ago)
Line 
1diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
2--- a/django/db/backends/creation.py
3+++ b/django/db/backends/creation.py
4@@ -462,3 +462,17 @@
5     def sql_table_creation_suffix(self):
6         "SQL to append to the end of the test table creation statements"
7         return ''
8+
9+    def test_db_signature(self):
10+        """
11+        Returns a tuple with elements of self.connection.settings_dict (a
12+        DATABASES setting value) that uniquely identify a database
13+        accordingly to the RDBMS particularities.
14+        """
15+        settings_dict = self.connection.settings_dict
16+        return (
17+            settings_dict['HOST'],
18+            settings_dict['PORT'],
19+            settings_dict['ENGINE'],
20+            settings_dict['NAME']
21+        )
22diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py
23--- a/django/db/backends/oracle/creation.py
24+++ b/django/db/backends/oracle/creation.py
25@@ -259,3 +259,13 @@
26         names as handled by Django haven't real counterparts in Oracle.
27         """
28         return self.connection.settings_dict['NAME']
29+
30+    def test_db_signature(self):
31+        settings_dict = self.connection.settings_dict
32+        return (
33+            settings_dict['HOST'],
34+            settings_dict['PORT'],
35+            settings_dict['ENGINE'],
36+            settings_dict['NAME'],
37+            settings_dict['TEST_TBLSPACE'],
38+        )
39diff --git a/django/test/simple.py b/django/test/simple.py
40--- a/django/test/simple.py
41+++ b/django/test/simple.py
42@@ -1,6 +1,3 @@
43-import sys
44-import signal
45-
46 from django.conf import settings
47 from django.core.exceptions import ImproperlyConfigured
48 from django.db.models import get_app, get_apps
49@@ -203,7 +200,7 @@
50         deferred = []
51 
52         while test_databases:
53-            signature, aliases = test_databases.pop()
54+            signature, (db_name, aliases) = test_databases.pop()
55             dependencies_satisfied = True
56             for alias in aliases:
57                 if alias in dependencies:
58@@ -217,10 +214,10 @@
59                     resolved_databases.add(alias)
60 
61             if dependencies_satisfied:
62-                ordered_test_databases.append((signature, aliases))
63+                ordered_test_databases.append((signature, (db_name, aliases)))
64                 changed = True
65             else:
66-                deferred.append((signature, aliases))
67+                deferred.append((signature, (db_name, aliases)))
68 
69         if not changed:
70             raise ImproperlyConfigured("Circular dependency in TEST_DEPENDENCIES")
71@@ -276,12 +273,11 @@
72                 # Store a tuple with DB parameters that uniquely identify it.
73                 # If we have two aliases with the same values for that tuple,
74                 # we only need to create the test database once.
75-                test_databases.setdefault((
76-                        connection.settings_dict['HOST'],
77-                        connection.settings_dict['PORT'],
78-                        connection.settings_dict['ENGINE'],
79-                        connection.settings_dict['NAME'],
80-                    ), []).append(alias)
81+                item = test_databases.setdefault(
82+                    connection.creation.test_db_signature(),
83+                    (connection.settings_dict['NAME'], [])
84+                )
85+                item[1].append(alias)
86 
87                 if 'TEST_DEPENDENCIES' in connection.settings_dict:
88                     dependencies[alias] = connection.settings_dict['TEST_DEPENDENCIES']
89@@ -292,7 +288,7 @@
90         # Second pass -- actually create the databases.
91         old_names = []
92         mirrors = []
93-        for (host, port, engine, db_name), aliases in dependency_ordered(test_databases.items(), dependencies):
94+        for signature, (db_name, aliases) in dependency_ordered(test_databases.items(), dependencies):
95             # Actually create the database for the first connection
96             connection = connections[aliases[0]]
97             old_names.append((connection, db_name, True))
98diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py
99--- a/tests/regressiontests/test_runner/tests.py
100+++ b/tests/regressiontests/test_runner/tests.py
101@@ -33,9 +33,9 @@
102 
103     def test_simple_dependencies(self):
104         raw = [
105-            ('s1', ['alpha']),
106-            ('s2', ['bravo']),
107-            ('s3', ['charlie']),
108+            ('s1', ('s1_db', ['alpha'])),
109+            ('s2', ('s2_db', ['bravo'])),
110+            ('s3', ('s3_db', ['charlie'])),
111         ]
112         dependencies = {
113             'alpha': ['charlie'],
114@@ -43,7 +43,7 @@
115         }
116 
117         ordered = simple.dependency_ordered(raw, dependencies=dependencies)
118-        ordered_sigs = [sig for sig,aliases in ordered]
119+        ordered_sigs = [sig for sig,value in ordered]
120 
121         self.assertIn('s1', ordered_sigs)
122         self.assertIn('s2', ordered_sigs)
123@@ -53,9 +53,9 @@
124 
125     def test_chained_dependencies(self):
126         raw = [
127-            ('s1', ['alpha']),
128-            ('s2', ['bravo']),
129-            ('s3', ['charlie']),
130+            ('s1', ('s1_db', ['alpha'])),
131+            ('s2', ('s2_db', ['bravo'])),
132+            ('s3', ('s3_db', ['charlie'])),
133         ]
134         dependencies = {
135             'alpha': ['bravo'],
136@@ -63,7 +63,7 @@
137         }
138 
139         ordered = simple.dependency_ordered(raw, dependencies=dependencies)
140-        ordered_sigs = [sig for sig,aliases in ordered]
141+        ordered_sigs = [sig for sig,value in ordered]
142 
143         self.assertIn('s1', ordered_sigs)
144         self.assertIn('s2', ordered_sigs)
145@@ -78,10 +78,10 @@
146 
147     def test_multiple_dependencies(self):
148         raw = [
149-            ('s1', ['alpha']),
150-            ('s2', ['bravo']),
151-            ('s3', ['charlie']),
152-            ('s4', ['delta']),
153+            ('s1', ('s1_db', ['alpha'])),
154+            ('s2', ('s2_db', ['bravo'])),
155+            ('s3', ('s3_db', ['charlie'])),
156+            ('s4', ('s4_db', ['delta'])),
157         ]
158         dependencies = {
159             'alpha': ['bravo','delta'],
160@@ -108,8 +108,8 @@
161 
162     def test_circular_dependencies(self):
163         raw = [
164-            ('s1', ['alpha']),
165-            ('s2', ['bravo']),
166+            ('s1', ('s1_db', ['alpha'])),
167+            ('s2', ('s2_db', ['bravo'])),
168         ]
169         dependencies = {
170             'bravo': ['alpha'],