Fixed #17786 (again) -- Ensured destruction of test databases works under Oracle, even with multiple databases, after r17411.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17601 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Aymeric Augustin 2012-02-28 21:23:45 +00:00
parent de9942a667
commit 97061bdf30
2 changed files with 8 additions and 14 deletions

View File

@ -353,7 +353,7 @@ class BaseDatabaseCreation(object):
def destroy_test_db(self, old_database_name, verbosity=1): def destroy_test_db(self, old_database_name, verbosity=1):
""" """
Destroy a test database, prompting the user for confirmation if the Destroy a test database, prompting the user for confirmation if the
database already exists. Returns the name of the test database created. database already exists.
""" """
self.connection.close() self.connection.close()
test_database_name = self.connection.settings_dict['NAME'] test_database_name = self.connection.settings_dict['NAME']
@ -367,7 +367,7 @@ class BaseDatabaseCreation(object):
# Temporarily use a new connection and a copy of the settings dict. # Temporarily use a new connection and a copy of the settings dict.
# This prevents the production database from being exposed to potential # This prevents the production database from being exposed to potential
# child threads while (or after) the test database is destroyed. # child threads while (or after) the test database is destroyed.
# Refs #10868. # Refs #10868 and #17786.
settings_dict = self.connection.settings_dict.copy() settings_dict = self.connection.settings_dict.copy()
settings_dict['NAME'] = old_database_name settings_dict['NAME'] = old_database_name
backend = load_backend(settings_dict['ENGINE']) backend = load_backend(settings_dict['ENGINE'])

View File

@ -40,11 +40,6 @@ class DatabaseCreation(BaseDatabaseCreation):
'URLField': 'VARCHAR2(%(max_length)s)', 'URLField': 'VARCHAR2(%(max_length)s)',
} }
# This dictionary stores the original values of user and passwd, which are
# changed during the tests. It's stored at the class level because the
# test database is created and destroyed by different connections (#17786).
remember = {}
def __init__(self, connection): def __init__(self, connection):
super(DatabaseCreation, self).__init__(connection) super(DatabaseCreation, self).__init__(connection)
@ -63,9 +58,6 @@ class DatabaseCreation(BaseDatabaseCreation):
'tblspace_temp': TEST_TBLSPACE_TMP, 'tblspace_temp': TEST_TBLSPACE_TMP,
} }
self.remember['user'] = self.connection.settings_dict['USER']
self.remember['passwd'] = self.connection.settings_dict['PASSWORD']
cursor = self.connection.cursor() cursor = self.connection.cursor()
if self._test_database_create(): if self._test_database_create():
try: try:
@ -111,8 +103,10 @@ class DatabaseCreation(BaseDatabaseCreation):
print "Tests cancelled." print "Tests cancelled."
sys.exit(1) sys.exit(1)
self.connection.settings_dict['TEST_USER'] = self.connection.settings_dict["USER"] = TEST_USER self.connection.settings_dict['SAVED_USER'] = self.connection.settings_dict['USER']
self.connection.settings_dict["PASSWORD"] = TEST_PASSWD self.connection.settings_dict['SAVED_PASSWORD'] = self.connection.settings_dict['PASSWORD']
self.connection.settings_dict['TEST_USER'] = self.connection.settings_dict['USER'] = TEST_USER
self.connection.settings_dict['PASSWORD'] = TEST_PASSWD
return self.connection.settings_dict['NAME'] return self.connection.settings_dict['NAME']
@ -127,8 +121,8 @@ class DatabaseCreation(BaseDatabaseCreation):
TEST_TBLSPACE = self._test_database_tblspace() TEST_TBLSPACE = self._test_database_tblspace()
TEST_TBLSPACE_TMP = self._test_database_tblspace_tmp() TEST_TBLSPACE_TMP = self._test_database_tblspace_tmp()
self.connection.settings_dict["USER"] = self.remember['user'] self.connection.settings_dict['USER'] = self.connection.settings_dict['SAVED_USER']
self.connection.settings_dict["PASSWORD"] = self.remember['passwd'] self.connection.settings_dict['PASSWORD'] = self.connection.settings_dict['SAVED_PASSWORD']
parameters = { parameters = {
'dbname': TEST_NAME, 'dbname': TEST_NAME,