summaryrefslogtreecommitdiff
path: root/django/test/utils.py
diff options
context:
space:
mode:
authorJason Pellerin <jpellerin@gmail.com>2006-09-14 20:18:24 +0000
committerJason Pellerin <jpellerin@gmail.com>2006-09-14 20:18:24 +0000
commitb92f683f2dee195cc23c7aa13e973fecd6ab35a7 (patch)
tree9b586e31dfbded7f99951dad4f21d931ee9ac2b6 /django/test/utils.py
parent432070d0fbf20b800e667012fd220ae26e3f579f (diff)
[multi-db] Fixed bugs in handling of pending references. Fixed dropping of test database, and ensured that it drops even if syncdb() fails.
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3760 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test/utils.py')
-rw-r--r--django/test/utils.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/django/test/utils.py b/django/test/utils.py
index d7a4a9c963..1a144031ab 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -66,19 +66,19 @@ def create_test_db(verbosity=1, autoclobber=False):
cursor = connection.cursor()
_set_autocommit(connection)
try:
- cursor.execute("CREATE DATABASE %s" % qn(db_name))
+ cursor.execute("CREATE DATABASE %s" % qn(TEST_DATABASE_NAME))
except Exception, e:
sys.stderr.write("Got an error creating the test database: %s\n" % e)
if not autoclobber:
- confirm = raw_input("It appears the test database, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % db_name)
+ confirm = raw_input("It appears the test database, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % TEST_DATABASE_NAME)
if autoclobber or confirm == 'yes':
try:
if verbosity >= 1:
print "Destroying old test database..."
- cursor.execute("DROP DATABASE %s" % qn(db_name))
+ cursor.execute("DROP DATABASE %s" % qn(TEST_DATABASE_NAME))
if verbosity >= 1:
print "Creating test database..."
- cursor.execute("CREATE DATABASE %s" % qn(db_name))
+ cursor.execute("CREATE DATABASE %s" % qn(TEST_DATABASE_NAME))
except Exception, e:
sys.stderr.write("Got an error recreating the test database: %s\n" % e)
sys.exit(2)
@@ -118,12 +118,15 @@ def destroy_test_db(old_database_name, old_databases, verbosity=1):
# connected to it.
if verbosity >= 1:
print "Destroying test database..."
- connection.close()
+ for cnx in connections.keys():
+ connections[cnx].close()
TEST_DATABASE_NAME = settings.DATABASE_NAME
settings.DATABASE_NAME = old_database_name
if settings.DATABASE_ENGINE != "sqlite3":
settings.OTHER_DATABASES = old_databases
+ for cnx in connections.keys():
+ connections[cnx].connection.cursor()
cursor = connection.cursor()
_set_autocommit(connection)
time.sleep(1) # To avoid "database is being accessed by other users" errors.