|
29
|
1 |
""" |
|
|
2 |
Backend for test environment. |
|
|
3 |
""" |
|
|
4 |
|
|
|
5 |
from django.core import mail |
|
|
6 |
from django.core.mail.backends.base import BaseEmailBackend |
|
|
7 |
|
|
|
8 |
class EmailBackend(BaseEmailBackend): |
|
|
9 |
"""A email backend for use during test sessions. |
|
|
10 |
|
|
|
11 |
The test connection stores email messages in a dummy outbox, |
|
|
12 |
rather than sending them out on the wire. |
|
|
13 |
|
|
|
14 |
The dummy outbox is accessible through the outbox instance attribute. |
|
|
15 |
""" |
|
|
16 |
def __init__(self, *args, **kwargs): |
|
|
17 |
super(EmailBackend, self).__init__(*args, **kwargs) |
|
|
18 |
if not hasattr(mail, 'outbox'): |
|
|
19 |
mail.outbox = [] |
|
|
20 |
|
|
|
21 |
def send_messages(self, messages): |
|
|
22 |
"""Redirect messages to the dummy outbox""" |
|
|
23 |
mail.outbox.extend(messages) |
|
|
24 |
return len(messages) |