Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15029 -- Moved to database backends the ability to decide if t…

…wo 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
  • Loading branch information...
commit dc5f2607deb35022523fef17dcd8479ca812e887 1 parent 77030cc
Ramiro Morales authored February 02, 2011
14  django/db/backends/creation.py
@@ -476,3 +476,17 @@ def set_autocommit(self):
476 476
     def sql_table_creation_suffix(self):
477 477
         "SQL to append to the end of the test table creation statements"
478 478
         return ''
  479
+
  480
+    def test_db_signature(self):
  481
+        """
  482
+        Returns a tuple with elements of self.connection.settings_dict (a
  483
+        DATABASES setting value) that uniquely identify a database
  484
+        accordingly to the RDBMS particularities.
  485
+        """
  486
+        settings_dict = self.connection.settings_dict
  487
+        return (
  488
+            settings_dict['HOST'],
  489
+            settings_dict['PORT'],
  490
+            settings_dict['ENGINE'],
  491
+            settings_dict['NAME']
  492
+        )
10  django/db/backends/oracle/creation.py
@@ -259,3 +259,13 @@ def _get_test_db_name(self):
259 259
         names as handled by Django haven't real counterparts in Oracle.
260 260
         """
261 261
         return self.connection.settings_dict['NAME']
  262
+
  263
+    def test_db_signature(self):
  264
+        settings_dict = self.connection.settings_dict
  265
+        return (
  266
+            settings_dict['HOST'],
  267
+            settings_dict['PORT'],
  268
+            settings_dict['ENGINE'],
  269
+            settings_dict['NAME'],
  270
+            settings_dict['TEST_USER'],
  271
+        )
22  django/test/simple.py
... ...
@@ -1,6 +1,3 @@
1  
-import sys
2  
-import signal
3  
-
4 1
 from django.conf import settings
5 2
 from django.core.exceptions import ImproperlyConfigured
6 3
 from django.db.models import get_app, get_apps
@@ -203,7 +200,7 @@ def dependency_ordered(test_databases, dependencies):
203 200
         deferred = []
204 201
 
205 202
         while test_databases:
206  
-            signature, aliases = test_databases.pop()
  203
+            signature, (db_name, aliases) = test_databases.pop()
207 204
             dependencies_satisfied = True
208 205
             for alias in aliases:
209 206
                 if alias in dependencies:
@@ -217,10 +214,10 @@ def dependency_ordered(test_databases, dependencies):
217 214
                     resolved_databases.add(alias)
218 215
 
219 216
             if dependencies_satisfied:
220  
-                ordered_test_databases.append((signature, aliases))
  217
+                ordered_test_databases.append((signature, (db_name, aliases)))
221 218
                 changed = True
222 219
             else:
223  
-                deferred.append((signature, aliases))
  220
+                deferred.append((signature, (db_name, aliases)))
224 221
 
225 222
         if not changed:
226 223
             raise ImproperlyConfigured("Circular dependency in TEST_DEPENDENCIES")
@@ -276,12 +273,11 @@ def setup_databases(self, **kwargs):
276 273
                 # Store a tuple with DB parameters that uniquely identify it.
277 274
                 # If we have two aliases with the same values for that tuple,
278 275
                 # we only need to create the test database once.
279  
-                test_databases.setdefault((
280  
-                        connection.settings_dict['HOST'],
281  
-                        connection.settings_dict['PORT'],
282  
-                        connection.settings_dict['ENGINE'],
283  
-                        connection.settings_dict['NAME'],
284  
-                    ), []).append(alias)
  276
+                item = test_databases.setdefault(
  277
+                    connection.creation.test_db_signature(),
  278
+                    (connection.settings_dict['NAME'], [])
  279
+                )
  280
+                item[1].append(alias)
285 281
 
286 282
                 if 'TEST_DEPENDENCIES' in connection.settings_dict:
287 283
                     dependencies[alias] = connection.settings_dict['TEST_DEPENDENCIES']
@@ -292,7 +288,7 @@ def setup_databases(self, **kwargs):
292 288
         # Second pass -- actually create the databases.
293 289
         old_names = []
294 290
         mirrors = []
295  
-        for (host, port, engine, db_name), aliases in dependency_ordered(test_databases.items(), dependencies):
  291
+        for signature, (db_name, aliases) in dependency_ordered(test_databases.items(), dependencies):
296 292
             # Actually create the database for the first connection
297 293
             connection = connections[aliases[0]]
298 294
             old_names.append((connection, db_name, True))
28  tests/regressiontests/test_runner/tests.py
@@ -33,9 +33,9 @@ class DependencyOrderingTests(unittest.TestCase):
33 33
 
34 34
     def test_simple_dependencies(self):
35 35
         raw = [
36  
-            ('s1', ['alpha']),
37  
-            ('s2', ['bravo']),
38  
-            ('s3', ['charlie']),
  36
+            ('s1', ('s1_db', ['alpha'])),
  37
+            ('s2', ('s2_db', ['bravo'])),
  38
+            ('s3', ('s3_db', ['charlie'])),
39 39
         ]
40 40
         dependencies = {
41 41
             'alpha': ['charlie'],
@@ -43,7 +43,7 @@ def test_simple_dependencies(self):
43 43
         }
44 44
 
45 45
         ordered = simple.dependency_ordered(raw, dependencies=dependencies)
46  
-        ordered_sigs = [sig for sig,aliases in ordered]
  46
+        ordered_sigs = [sig for sig,value in ordered]
47 47
 
48 48
         self.assertIn('s1', ordered_sigs)
49 49
         self.assertIn('s2', ordered_sigs)
@@ -53,9 +53,9 @@ def test_simple_dependencies(self):
53 53
 
54 54
     def test_chained_dependencies(self):
55 55
         raw = [
56  
-            ('s1', ['alpha']),
57  
-            ('s2', ['bravo']),
58  
-            ('s3', ['charlie']),
  56
+            ('s1', ('s1_db', ['alpha'])),
  57
+            ('s2', ('s2_db', ['bravo'])),
  58
+            ('s3', ('s3_db', ['charlie'])),
59 59
         ]
60 60
         dependencies = {
61 61
             'alpha': ['bravo'],
@@ -63,7 +63,7 @@ def test_chained_dependencies(self):
63 63
         }
64 64
 
65 65
         ordered = simple.dependency_ordered(raw, dependencies=dependencies)
66  
-        ordered_sigs = [sig for sig,aliases in ordered]
  66
+        ordered_sigs = [sig for sig,value in ordered]
67 67
 
68 68
         self.assertIn('s1', ordered_sigs)
69 69
         self.assertIn('s2', ordered_sigs)
@@ -78,10 +78,10 @@ def test_chained_dependencies(self):
78 78
 
79 79
     def test_multiple_dependencies(self):
80 80
         raw = [
81  
-            ('s1', ['alpha']),
82  
-            ('s2', ['bravo']),
83  
-            ('s3', ['charlie']),
84  
-            ('s4', ['delta']),
  81
+            ('s1', ('s1_db', ['alpha'])),
  82
+            ('s2', ('s2_db', ['bravo'])),
  83
+            ('s3', ('s3_db', ['charlie'])),
  84
+            ('s4', ('s4_db', ['delta'])),
85 85
         ]
86 86
         dependencies = {
87 87
             'alpha': ['bravo','delta'],
@@ -108,8 +108,8 @@ def test_multiple_dependencies(self):
108 108
 
109 109
     def test_circular_dependencies(self):
110 110
         raw = [
111  
-            ('s1', ['alpha']),
112  
-            ('s2', ['bravo']),
  111
+            ('s1', ('s1_db', ['alpha'])),
  112
+            ('s2', ('s2_db', ['bravo'])),
113 113
         ]
114 114
         dependencies = {
115 115
             'bravo': ['alpha'],

0 notes on commit dc5f260

Please sign in to comment.
Something went wrong with that request. Please try again.