Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed error introduced in r14666 that results in the message reportin…

…g 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
  • Loading branch information...
commit e0d8c5fca26bbe20cc26226e794dbb0e61a3467b 1 parent a4898dc
@ramiro ramiro authored
View
22 django/db/backends/creation.py
@@ -32,8 +32,6 @@ def sql_create_model(self, model, style, known_models=set()):
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 @@ def create_test_db(self, verbosity=1, autoclobber=False):
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 @@ def create_test_db(self, verbosity=1, autoclobber=False):
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 @@ def create_test_db(self, verbosity=1, autoclobber=False):
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
4 django/db/backends/oracle/creation.py
@@ -43,7 +43,7 @@ def __init__(self, connection):
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 @@ def _execute_statements(self, cursor, statements, parameters, verbosity):
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
12 django/db/backends/sqlite3/creation.py
@@ -38,9 +38,15 @@ def sql_remove_table_constraints(self, model, references_to_delete, style):
"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 @@ def _create_test_db(self, verbosity, autoclobber):
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):
Please sign in to comment.
Something went wrong with that request. Please try again.