summaryrefslogtreecommitdiff
path: root/django/test/utils.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2006-09-02 09:26:24 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2006-09-02 09:26:24 +0000
commitd043200077244cfcc2b204dbb173d5d494d16f60 (patch)
tree821d6cb84d88f9d77b10fa75a0b68e6997891296 /django/test/utils.py
parentd78e2ae3557feb1c9374cc56f6c130b13a7ef789 (diff)
Refs #2333 - Re-added the template rendering signal for testing purposes; however, the signal is not available during normal operation. It is only added as part of an instrumentation step that occurs during test framework setup. Previous attempt (r3659) was reverted (r3666) due to performance concerns.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3707 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test/utils.py')
-rw-r--r--django/test/utils.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/django/test/utils.py b/django/test/utils.py
index 6d6827918d..1bb448f41b 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -1,11 +1,40 @@
import sys, time
from django.conf import settings
from django.db import connection, transaction, backend
+from django.dispatch import dispatcher
+from django.test import signals
+from django.template import Template
# The prefix to put on the default database name when creating
# the test database.
TEST_DATABASE_PREFIX = 'test_'
+def instrumented_test_render(self, context):
+ """An instrumented Template render method, providing a signal
+ that can be intercepted by the test system Client
+
+ """
+ dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context)
+ return self.nodelist.render(context)
+
+def setup_test_environment():
+ """Perform any global pre-test setup. This involves:
+
+ - Installing the instrumented test renderer
+
+ """
+ Template.original_render = Template.render
+ Template.render = instrumented_test_render
+
+def teardown_test_environment():
+ """Perform any global post-test teardown. This involves:
+
+ - Restoring the original test renderer
+
+ """
+ Template.render = Template.original_render
+ del Template.original_render
+
def _set_autocommit(connection):
"Make sure a connection is in autocommit mode."
if hasattr(connection.connection, "autocommit"):
@@ -75,4 +104,3 @@ def destroy_test_db(old_database_name, verbosity=1):
time.sleep(1) # To avoid "database is being accessed by other users" errors.
cursor.execute("DROP DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME))
connection.close()
-