Ticket #20681: 0002-Don-t-try-to-tear-down-aliases-for-test-databases-it.patch

File 0002-Don-t-try-to-tear-down-aliases-for-test-databases-it.patch, 2.6 KB (added by simonpercivall, 2 years ago)

patch with test case

  • django/test/simple.py

    diff --git a/django/test/simple.py b/django/test/simple.py
    index bf0219d..e19e8c7 100644
    a b class DjangoTestSuiteRunner(object): 
    309309
    310310            for alias in aliases:
    311311                connection = connections[alias]
    312                 old_names.append((connection, db_name, True))
    313312                if test_db_name is None:
     313                    old_names.append((connection, db_name, True))
    314314                    test_db_name = connection.creation.create_test_db(
    315315                            self.verbosity, autoclobber=not self.interactive)
    316316                else:
     317                    old_names.append((connection, db_name, False))
    317318                    connection.settings_dict['NAME'] = test_db_name
    318319
    319320        for alias, mirror_alias in mirrored_aliases.items():
  • tests/regressiontests/test_runner/tests.py

    diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py
    index b5e4a1d..a61d071 100644
    a b class DummyBackendTest(unittest.TestCase): 
    285285            db.connections = old_db_connections
    286286
    287287
     288class AliasedDatabaseTest(unittest.TestCase):
     289    def test_setup_aliased_databases(self):
     290        from django.db.backends.dummy.base import DatabaseCreation
     291
     292        runner = DjangoTestSuiteRunner(verbosity=0)
     293        old_db_connections = db.connections
     294        old_destroy_test_db = DatabaseCreation.destroy_test_db
     295        old_create_test_db = DatabaseCreation.create_test_db
     296        try:
     297            destroyed_names = []
     298            DatabaseCreation.destroy_test_db = lambda self, old_database_name, verbosity=1: destroyed_names.append(old_database_name)
     299            DatabaseCreation.create_test_db = lambda self, verbosity=1, autoclobber=False: self._get_test_db_name()
     300
     301            db.connections = db.ConnectionHandler({
     302                'default': {
     303                    'ENGINE': 'django.db.backends.dummy',
     304                    'NAME': 'dbname',
     305                },
     306                'other': {
     307                    'ENGINE': 'django.db.backends.dummy',
     308                    'NAME': 'dbname',
     309                }
     310            })
     311
     312            old_config = runner.setup_databases()
     313            runner.teardown_databases(old_config)
     314
     315            self.assertEquals(destroyed_names.count('dbname'), 1)
     316        finally:
     317            DatabaseCreation.create_test_db = old_create_test_db
     318            DatabaseCreation.destroy_test_db = old_destroy_test_db
     319            db.connections = old_db_connections
     320
     321
    288322class DeprecationDisplayTest(AdminScriptTestCase):
    289323    # tests for 19546
    290324    def setUp(self):
Back to Top