Fixed #23652 -- Restored database name after destroying test database

Thanks Bjarkias for the report.
This commit is contained in:
Claude Paroz 2014-10-24 14:53:58 +02:00
parent 1bdf1cb1c0
commit 45db842c9b
2 changed files with 17 additions and 0 deletions

View File

@ -524,6 +524,10 @@ class BaseDatabaseCreation(object):
if not keepdb:
self._destroy_test_db(test_database_name, verbosity)
# Restore the original database name
settings.DATABASES[self.connection.alias]["NAME"] = old_database_name
self.connection.settings_dict["NAME"] = old_database_name
def _destroy_test_db(self, test_database_name, verbosity):
"""
Internal implementation - remove the test db tables.

View File

@ -6,6 +6,7 @@ from __future__ import unicode_literals
import unittest
from django import db
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django.db.backends.dummy.base import DatabaseCreation
@ -336,6 +337,18 @@ class SetupDatabasesTests(unittest.TestCase):
self.assertEqual(destroyed_names.count('dbname'), 1)
def test_destroy_test_db_restores_db_name(self):
db.connections = db.ConnectionHandler({
'default': {
'ENGINE': settings.DATABASES[db.DEFAULT_DB_ALIAS]["ENGINE"],
'NAME': 'xxx_test_database',
},
})
# Using the real current name as old_name to not mess with the test suite.
old_name = settings.DATABASES[db.DEFAULT_DB_ALIAS]["NAME"]
db.connections['default'].creation.destroy_test_db(old_name, verbosity=0, keepdb=True)
self.assertEqual(db.connections['default'].settings_dict["NAME"], old_name)
def test_serialization(self):
serialize = []
DatabaseCreation.create_test_db = (