Fixed error introduced in r14666 that results in the message reporting the test DB name to be created being shown actually after the real action when the operation fails.

Implemented that by factoring out calculation of test DB name to an internal method.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14861 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Ramiro Morales 2010-12-08 23:48:28 +00:00
parent a4898dc50b
commit e0d8c5fca2
3 changed files with 25 additions and 13 deletions

View File

@ -32,8 +32,6 @@ class BaseDatabaseCreation(object):
Returns the SQL required to create a single model, as a tuple of:
(list_of_sql, pending_references_dict)
"""
from django.db import models
opts = model._meta
if not opts.managed or opts.proxy:
return [], {}
@ -340,7 +338,7 @@ class BaseDatabaseCreation(object):
Creates a test database, prompting the user for confirmation if the
database already exists. Returns the name of the test database created.
"""
test_database_name = self._create_test_db(verbosity, autoclobber)
test_database_name = self._get_test_db_name()
if verbosity >= 1:
test_db_repr = ''
@ -348,6 +346,8 @@ class BaseDatabaseCreation(object):
test_db_repr = " ('%s')" % test_database_name
print "Creating test database for alias '%s'%s..." % (self.connection.alias, test_db_repr)
self._create_test_db(verbosity, autoclobber)
self.connection.close()
self.connection.settings_dict["NAME"] = test_database_name
@ -372,14 +372,22 @@ class BaseDatabaseCreation(object):
return test_database_name
def _get_test_db_name(self):
"""
Internal implementation - returns the name of the test DB that wll be
created. Only useful when called from create_test_db() and
_create_test_db() and when no external munging is done with the 'NAME'
or 'TEST_NAME' settings.
"""
if self.connection.settings_dict['TEST_NAME']:
return self.connection.settings_dict['TEST_NAME']
return TEST_DATABASE_PREFIX + self.connection.settings_dict['NAME']
def _create_test_db(self, verbosity, autoclobber):
"Internal implementation - creates the test db tables."
suffix = self.sql_table_creation_suffix()
if self.connection.settings_dict['TEST_NAME']:
test_database_name = self.connection.settings_dict['TEST_NAME']
else:
test_database_name = TEST_DATABASE_PREFIX + self.connection.settings_dict['NAME']
test_database_name = self._get_test_db_name()
qn = self.connection.ops.quote_name

View File

@ -43,7 +43,7 @@ class DatabaseCreation(BaseDatabaseCreation):
super(DatabaseCreation, self).__init__(connection)
def _create_test_db(self, verbosity=1, autoclobber=False):
TEST_NAME = self._test_database_name()
TEST_NAME = self._get_test_db_name()
TEST_USER = self._test_database_user()
TEST_PASSWD = self._test_database_passwd()
TEST_TBLSPACE = self._test_database_tblspace()
@ -201,7 +201,7 @@ class DatabaseCreation(BaseDatabaseCreation):
sys.stderr.write("Failed (%s)\n" % (err))
raise
def _test_database_name(self):
def _get_test_db_name(self):
name = TEST_DATABASE_PREFIX + self.connection.settings_dict['NAME']
try:
if self.connection.settings_dict['TEST_NAME']:

View File

@ -38,9 +38,15 @@ class DatabaseCreation(BaseDatabaseCreation):
"SQLite3 doesn't support constraints"
return []
def _create_test_db(self, verbosity, autoclobber):
def _get_test_db_name(self):
test_database_name = self.connection.settings_dict['TEST_NAME']
if test_database_name and test_database_name != ":memory:":
if test_database_name and test_database_name != ':memory:':
return test_database_name
return ':memory:'
def _create_test_db(self, verbosity, autoclobber):
test_database_name = self._get_test_db_name()
if test_database_name != ':memory:':
# Erase the old test database
if verbosity >= 1:
print "Destroying old test database '%s'..." % self.connection.alias
@ -56,8 +62,6 @@ class DatabaseCreation(BaseDatabaseCreation):
else:
print "Tests cancelled."
sys.exit(1)
else:
test_database_name = ":memory:"
return test_database_name
def _destroy_test_db(self, test_database_name, verbosity):