diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py index 2cc239d969..b6379df4c1 100644 --- a/django/db/backends/creation.py +++ b/django/db/backends/creation.py @@ -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 diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py index 82918b04b1..8a4458b310 100644 --- a/django/db/backends/oracle/creation.py +++ b/django/db/backends/oracle/creation.py @@ -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']: diff --git a/django/db/backends/sqlite3/creation.py b/django/db/backends/sqlite3/creation.py index a65db1160b..f32bd0a75d 100644 --- a/django/db/backends/sqlite3/creation.py +++ b/django/db/backends/sqlite3/creation.py @@ -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):