Ticket #15029: 15029.2.diff

File 15029.2.diff, 6.4 KB (added by Ramiro Morales, 14 years ago)

Patch modified with change suggested by Ian

  • django/db/backends/creation.py

    diff -r 8c28c8ad3b3f django/db/backends/creation.py
    a b  
    476476    def sql_table_creation_suffix(self):
    477477        "SQL to append to the end of the test table creation statements"
    478478        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        )
  • django/db/backends/oracle/creation.py

    diff -r 8c28c8ad3b3f django/db/backends/oracle/creation.py
    a b  
    259259        names as handled by Django haven't real counterparts in Oracle.
    260260        """
    261261        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        )
  • django/test/simple.py

    diff -r 8c28c8ad3b3f django/test/simple.py
    a b  
    1 import sys
    2 import signal
    3 
    41from django.conf import settings
    52from django.core.exceptions import ImproperlyConfigured
    63from django.db.models import get_app, get_apps
     
    203200        deferred = []
    204201
    205202        while test_databases:
    206             signature, aliases = test_databases.pop()
     203            signature, (db_name, aliases) = test_databases.pop()
    207204            dependencies_satisfied = True
    208205            for alias in aliases:
    209206                if alias in dependencies:
     
    217214                    resolved_databases.add(alias)
    218215
    219216            if dependencies_satisfied:
    220                 ordered_test_databases.append((signature, aliases))
     217                ordered_test_databases.append((signature, (db_name, aliases)))
    221218                changed = True
    222219            else:
    223                 deferred.append((signature, aliases))
     220                deferred.append((signature, (db_name, aliases)))
    224221
    225222        if not changed:
    226223            raise ImproperlyConfigured("Circular dependency in TEST_DEPENDENCIES")
     
    276273                # Store a tuple with DB parameters that uniquely identify it.
    277274                # If we have two aliases with the same values for that tuple,
    278275                # 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)
    285281
    286282                if 'TEST_DEPENDENCIES' in connection.settings_dict:
    287283                    dependencies[alias] = connection.settings_dict['TEST_DEPENDENCIES']
     
    292288        # Second pass -- actually create the databases.
    293289        old_names = []
    294290        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):
    296292            # Actually create the database for the first connection
    297293            connection = connections[aliases[0]]
    298294            old_names.append((connection, db_name, True))
  • tests/regressiontests/test_runner/tests.py

    diff -r 8c28c8ad3b3f tests/regressiontests/test_runner/tests.py
    a b  
    3333
    3434    def test_simple_dependencies(self):
    3535        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'])),
    3939        ]
    4040        dependencies = {
    4141            'alpha': ['charlie'],
     
    4343        }
    4444
    4545        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]
    4747
    4848        self.assertIn('s1', ordered_sigs)
    4949        self.assertIn('s2', ordered_sigs)
     
    5353
    5454    def test_chained_dependencies(self):
    5555        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'])),
    5959        ]
    6060        dependencies = {
    6161            'alpha': ['bravo'],
     
    6363        }
    6464
    6565        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]
    6767
    6868        self.assertIn('s1', ordered_sigs)
    6969        self.assertIn('s2', ordered_sigs)
     
    7878
    7979    def test_multiple_dependencies(self):
    8080        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'])),
    8585        ]
    8686        dependencies = {
    8787            'alpha': ['bravo','delta'],
     
    108108
    109109    def test_circular_dependencies(self):
    110110        raw = [
    111             ('s1', ['alpha']),
    112             ('s2', ['bravo']),
     111            ('s1', ('s1_db', ['alpha'])),
     112            ('s2', ('s2_db', ['bravo'])),
    113113        ]
    114114        dependencies = {
    115115            'bravo': ['alpha'],
Back to Top