Ticket #20681: dont-try-to-tear-down-test-database-aliases.patch

File dont-try-to-tear-down-test-database-aliases.patch, 2.6 KB (added by anonymous, 22 months ago)

patch against master

  • django/test/runner.py

    diff --git a/django/test/runner.py b/django/test/runner.py
    index 98113e9..a1ff28f 100644
    a b def setup_databases(verbosity, interactive, **kwargs): 
    275275
    276276        for alias in aliases:
    277277            connection = connections[alias]
    278             old_names.append((connection, db_name, True))
    279278            if test_db_name is None:
     279                old_names.append((connection, db_name, True))
    280280                test_db_name = connection.creation.create_test_db(
    281281                        verbosity, autoclobber=not interactive)
    282282            else:
     283                old_names.append((connection, db_name, False))
    283284                connection.settings_dict['NAME'] = test_db_name
    284285
    285286    for alias, mirror_alias in mirrored_aliases.items():
  • tests/test_runner/tests.py

    diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py
    index 0c7c966..7765f97 100644
    a b class AliasedDefaultTestSetupTest(unittest.TestCase): 
    316316            db.connections = old_db_connections
    317317
    318318
     319class AliasedDatabaseTeardownTest(unittest.TestCase):
     320    def test_setup_aliased_databases(self):
     321        from django.db.backends.dummy.base import DatabaseCreation
     322
     323        runner_instance = runner.DiscoverRunner(verbosity=0)
     324        old_db_connections = db.connections
     325        old_destroy_test_db = DatabaseCreation.destroy_test_db
     326        old_create_test_db = DatabaseCreation.create_test_db
     327        try:
     328            destroyed_names = []
     329            DatabaseCreation.destroy_test_db = lambda self, old_database_name, verbosity=1: destroyed_names.append(old_database_name)
     330            DatabaseCreation.create_test_db = lambda self, verbosity=1, autoclobber=False: self._get_test_db_name()
     331
     332            db.connections = db.ConnectionHandler({
     333                'default': {
     334                    'ENGINE': 'django.db.backends.dummy',
     335                    'NAME': 'dbname',
     336                },
     337                'other': {
     338                    'ENGINE': 'django.db.backends.dummy',
     339                    'NAME': 'dbname',
     340                }
     341            })
     342
     343            old_config = runner_instance.setup_databases()
     344            runner_instance.teardown_databases(old_config)
     345
     346            self.assertEqual(destroyed_names.count('dbname'), 1)
     347        finally:
     348            DatabaseCreation.create_test_db = old_create_test_db
     349            DatabaseCreation.destroy_test_db = old_destroy_test_db
     350            db.connections = old_db_connections
     351
     352
    319353class DeprecationDisplayTest(AdminScriptTestCase):
    320354    # tests for 19546
    321355    def setUp(self):
Back to Top