Fix user_self calling editGet with a wrong parameter
[Melange.git] / app / django / test / utils.py
blob69bd25bc122db0630533f976ccff3fceb7ce6ca5
1 import sys, time, os
2 from django.conf import settings
3 from django.db import connection
4 from django.core import mail
5 from django.test import signals
6 from django.template import Template
7 from django.utils.translation import deactivate
9 def instrumented_test_render(self, context):
10 """
11 An instrumented Template render method, providing a signal
12 that can be intercepted by the test system Client
13 """
14 signals.template_rendered.send(sender=self, template=self, context=context)
15 return self.nodelist.render(context)
17 class TestSMTPConnection(object):
18 """A substitute SMTP connection for use during test sessions.
19 The test connection stores email messages in a dummy outbox,
20 rather than sending them out on the wire.
22 """
23 def __init__(*args, **kwargs):
24 pass
25 def open(self):
26 "Mock the SMTPConnection open() interface"
27 pass
28 def close(self):
29 "Mock the SMTPConnection close() interface"
30 pass
31 def send_messages(self, messages):
32 "Redirect messages to the dummy outbox"
33 mail.outbox.extend(messages)
34 return len(messages)
36 def setup_test_environment():
37 """Perform any global pre-test setup. This involves:
39 - Installing the instrumented test renderer
40 - Diverting the email sending functions to a test buffer
41 - Setting the active locale to match the LANGUAGE_CODE setting.
42 """
43 Template.original_render = Template.render
44 Template.render = instrumented_test_render
46 mail.original_SMTPConnection = mail.SMTPConnection
47 mail.SMTPConnection = TestSMTPConnection
49 mail.outbox = []
51 deactivate()
53 def teardown_test_environment():
54 """Perform any global post-test teardown. This involves:
56 - Restoring the original test renderer
57 - Restoring the email sending functions
59 """
60 Template.render = Template.original_render
61 del Template.original_render
63 mail.SMTPConnection = mail.original_SMTPConnection
64 del mail.original_SMTPConnection
66 del mail.outbox