summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-11-03 12:53:26 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-11-03 12:53:26 +0000
commitaba5389326372be43b2a3bdcda16646fd197e807 (patch)
treea296f56691d3cb6da4dcbc3a99e16a7eab9a7c43 /django/test
parent8287c27b1895ba56c6680295ff3d202fc7a4b64e (diff)
Fixed #10355 -- Added an API for pluggable e-mail backends.
Thanks to Andi Albrecht for his work on this patch, and to everyone else that contributed during design and development. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11709 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test')
-rw-r--r--django/test/utils.py30
1 files changed, 9 insertions, 21 deletions
diff --git a/django/test/utils.py b/django/test/utils.py
index d34dd33d15..a30bb7e41c 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -2,6 +2,7 @@ import sys, time, os
from django.conf import settings
from django.db import connection
from django.core import mail
+from django.core.mail.backends import locmem
from django.test import signals
from django.template import Template
from django.utils.translation import deactivate
@@ -28,37 +29,22 @@ def instrumented_test_render(self, context):
signals.template_rendered.send(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
- def open(self):
- "Mock the SMTPConnection open() interface"
- pass
- def close(self):
- "Mock the SMTPConnection close() interface"
- pass
- def send_messages(self, messages):
- "Redirect messages to the dummy outbox"
- mail.outbox.extend(messages)
- return len(messages)
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
+ - Set the email backend to the locmem email backend.
- Setting the active locale to match the LANGUAGE_CODE setting.
"""
Template.original_render = Template.render
Template.render = instrumented_test_render
mail.original_SMTPConnection = mail.SMTPConnection
- mail.SMTPConnection = TestSMTPConnection
+ mail.SMTPConnection = locmem.EmailBackend
+
+ settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem'
+ mail.original_email_backend = settings.EMAIL_BACKEND
mail.outbox = []
@@ -77,8 +63,10 @@ def teardown_test_environment():
mail.SMTPConnection = mail.original_SMTPConnection
del mail.original_SMTPConnection
- del mail.outbox
+ settings.EMAIL_BACKEND = mail.original_email_backend
+ del mail.original_email_backend
+ del mail.outbox
def get_runner(settings):
test_path = settings.TEST_RUNNER.split('.')