diff options
author | Adrian Holovaty <adrian@holovaty.com> | 2007-08-16 06:06:55 +0000 |
---|---|---|
committer | Adrian Holovaty <adrian@holovaty.com> | 2007-08-16 06:06:55 +0000 |
commit | 01adbb55e6698b512ff202bc5fc81f9565e4003b (patch) | |
tree | 9b9ab3f9fa4461665ff81546c840054a34c50d16 /django/test/utils.py | |
parent | 7f06e44f9959fd8c0db58162d4bd5feb383db8f1 (diff) | |
download | django-01adbb55e6698b512ff202bc5fc81f9565e4003b.tar.gz |
Major refactoring of django.core.management -- it's now a package rather than a 1730-line single module. All django-admin/manage.py commands are now stored in separate modules. This is backwards-incompatible for people who used django.core.management functions directly
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5898 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test/utils.py')
-rw-r--r-- | django/test/utils.py | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/django/test/utils.py b/django/test/utils.py index e9525b4dd4..ef88a19976 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -1,8 +1,8 @@ import sys, time from django.conf import settings from django.db import connection, backend, get_creation_module -from django.core import management, mail -from django.core import management, mail +from django.core import mail +from django.core.management import call_command from django.dispatch import dispatcher from django.test import signals from django.template import Template @@ -18,12 +18,12 @@ def instrumented_test_render(self, context): """ dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context) return self.nodelist.render(context) - + class TestSMTPConnection(object): """A substitute SMTP connection for use during test sessions. The test connection stores email messages in a dummy outbox, rather than sending them out on the wire. - + """ def __init__(*args, **kwargs): pass @@ -39,34 +39,34 @@ class TestSMTPConnection(object): def setup_test_environment(): """Perform any global pre-test setup. This involves: - + - Installing the instrumented test renderer - Diverting the email sending functions to a test buffer - + """ Template.original_render = Template.render Template.render = instrumented_test_render - + mail.original_SMTPConnection = mail.SMTPConnection mail.SMTPConnection = TestSMTPConnection mail.outbox = [] - + def teardown_test_environment(): """Perform any global post-test teardown. This involves: - Restoring the original test renderer - Restoring the email sending functions - + """ Template.render = Template.original_render del Template.original_render - + mail.SMTPConnection = mail.original_SMTPConnection del mail.original_SMTPConnection - + del mail.outbox - + def _set_autocommit(connection): "Make sure a connection is in autocommit mode." if hasattr(connection.connection, "autocommit"): @@ -94,7 +94,7 @@ def create_test_db(verbosity=1, autoclobber=False): if hasattr(creation_module, "create_test_db"): creation_module.create_test_db(settings, connection, backend, verbosity, autoclobber) return - + if verbosity >= 1: print "Creating test database..." # If we're using SQLite, it's more convenient to test against an @@ -112,22 +112,22 @@ def create_test_db(verbosity=1, autoclobber=False): TEST_DATABASE_NAME = settings.TEST_DATABASE_NAME else: TEST_DATABASE_NAME = TEST_DATABASE_PREFIX + settings.DATABASE_NAME - + # Create the test database and connect to it. We need to autocommit - # if the database supports it because PostgreSQL doesn't allow + # if the database supports it because PostgreSQL doesn't allow # CREATE/DROP DATABASE statements within transactions. cursor = connection.cursor() _set_autocommit(connection) try: cursor.execute("CREATE DATABASE %s %s" % (backend.quote_name(TEST_DATABASE_NAME), suffix)) - except Exception, e: + except Exception, e: sys.stderr.write("Got an error creating the test database: %s\n" % e) if not autoclobber: confirm = raw_input("Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: " % TEST_DATABASE_NAME) if autoclobber or confirm == 'yes': try: if verbosity >= 1: - print "Destroying old test database..." + print "Destroying old test database..." cursor.execute("DROP DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME)) if verbosity >= 1: print "Creating test database..." @@ -138,15 +138,15 @@ def create_test_db(verbosity=1, autoclobber=False): else: print "Tests cancelled." sys.exit(1) - + connection.close() settings.DATABASE_NAME = TEST_DATABASE_NAME - management.syncdb(verbosity, interactive=False) + call_command('syncdb', verbosity=verbosity, interactive=False) if settings.CACHE_BACKEND.startswith('db://'): cache_name = settings.CACHE_BACKEND[len('db://'):] - management.createcachetable(cache_name) + call_command('createcachetable', cache_name) # Get a cursor (even though we don't need one yet). This has # the side effect of initializing the test database. @@ -158,7 +158,7 @@ def destroy_test_db(old_database_name, verbosity=1): if hasattr(creation_module, "destroy_test_db"): creation_module.destroy_test_db(settings, connection, backend, old_database_name, verbosity) return - + # Unless we're using SQLite, remove the test database to clean up after # ourselves. Connect to the previous database (not the test database) # to do so, because it's not allowed to delete a database while being |