1
0
mirror of https://github.com/django/django.git synced 2025-07-05 02:09:13 +00:00

[multi-db] Added TEST_DATABASES tuple to runtests.py. Now, databases in TEST_DATABASES will be created (if they don't exist or if the user accepts) at the start of the test run and dropped at the end. Those databases will be assigned to settings.DATABASES, with settings other than the database name inherited either from the DATABASES property in the active settings file (if it is present and contains a matching key) or from the default database settings.

git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3263 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jason Pellerin 2006-07-03 20:47:33 +00:00
parent a206863cf6
commit 8f1d2bc98a

View File

@ -11,6 +11,7 @@ MODEL_TESTS_DIR_NAME = 'modeltests'
OTHER_TESTS_DIR = "othertests" OTHER_TESTS_DIR = "othertests"
REGRESSION_TESTS_DIR_NAME = 'regressiontests' REGRESSION_TESTS_DIR_NAME = 'regressiontests'
TEST_DATABASE_NAME = 'django_test_db' TEST_DATABASE_NAME = 'django_test_db'
TEST_DATABASES = (TEST_DATABASE_NAME + '_a', TEST_DATABASE_NAME + '_b')
error_list = [] error_list = []
def log_error(model_name, title, description): def log_error(model_name, title, description):
@ -164,25 +165,23 @@ class TestRunner:
self.old_database_name = settings.DATABASE_NAME self.old_database_name = settings.DATABASE_NAME
self.old_databases = settings.DATABASES self.old_databases = settings.DATABASES
db_a = TEST_DATABASE_NAME + '_a'
db_b = TEST_DATABASE_NAME + '_b'
if settings.DATABASE_ENGINE == 'sqlite3': if settings.DATABASE_ENGINE == 'sqlite3':
# If we're using SQLite, it's more convenient to test against an # If we're using SQLite, it's more convenient to test against an
# in-memory database. But we can only do this for the default; # in-memory database. But we can only do this for the default;
# after that we have to use temp files. # after that we have to use temp files.
TEST_DATABASE_NAME = ':memory:' TEST_DATABASE_NAME = ':memory:'
db_a_name = self._tempfile()
db_b_name = self._tempfile() new_databases = {}
self.cleanup_files.append(db_a_name) for db_name in TEST_DATABASES:
self.cleanup_files.append(db_b_name) db_st = settings.DATABASES.setdefault(db_name, {})
else: engine = db_st.get('DATABASE_ENGINE', settings.DATABASE_ENGINE)
db_a_name = db_a if engine == 'sqlite3':
db_b_name = db_b db_st['DATABASE_NAME'] = self._tempfile()
self.cleanup_files.append(db_st['DATABASE_NAME'])
settings.DATABASES = { else:
db_a: { 'DATABASE_NAME': db_a_name }, db_st['DATABASE_NAME'] = db_name
db_b: { 'DATABASE_NAME': db_b_name } new_databases[db_name] = db_st
} settings.DATABASES = new_databases
self.create_test_db(TEST_DATABASE_NAME, connection) self.create_test_db(TEST_DATABASE_NAME, connection)
for name, info in settings.DATABASES.items(): for name, info in settings.DATABASES.items():