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 , 11 years ago) |
---|
-
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): 275 275 276 276 for alias in aliases: 277 277 connection = connections[alias] 278 old_names.append((connection, db_name, True))279 278 if test_db_name is None: 279 old_names.append((connection, db_name, True)) 280 280 test_db_name = connection.creation.create_test_db( 281 281 verbosity, autoclobber=not interactive) 282 282 else: 283 old_names.append((connection, db_name, False)) 283 284 connection.settings_dict['NAME'] = test_db_name 284 285 285 286 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): 316 316 db.connections = old_db_connections 317 317 318 318 319 class 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 319 353 class DeprecationDisplayTest(AdminScriptTestCase): 320 354 # tests for 19546 321 355 def setUp(self):