forked from BradWhittington/django-mailgun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_django_mailgun.py
69 lines (55 loc) · 1.86 KB
/
test_django_mailgun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
from django.core.mail import EmailMessage
from django_mailgun import MailgunBackend
from pytest import raises
def test_no_configuration():
with raises(ImproperlyConfigured):
MailgunBackend()
def test_configuration():
settings.configure(
MAILGUN_ACCESS_KEY=123,
MAILGUN_SERVER_NAME='abc'
)
MailgunBackend()
def test_marker_methods():
# Already configured
mb = MailgunBackend()
assert mb.open() is None
assert mb.close() is None
def setUp():
mb = MailgunBackend(fail_silently=True)
message = EmailMessage()
return (mb, message)
def check_output_value(mb, message, test_input, expected_output):
for k, v in test_input.iteritems():
message.extra_headers[k] = v
output = mb._map_smtp_headers_to_api_parameters(message)
for extra_header in expected_output:
assert extra_header in output
def test_extra_headers_map():
mb, message = setUp()
test_input = {
'X-Mailgun-Tag': ['Tag 1', 'Tag 2'],
'X-Mailgun-Campaign-Id': "1",
'X-Mailgun-Dkim': 'yes',
'X-Mailgun-Deliver-By': 'Thu, 13 Oct 2011 18:02:00 GMT',
'X-Mailgun-Drop-Message': 'yes',
'X-Mailgun-Track': 'yes',
'X-Mailgun-Track-Clicks': 'htmlonly',
'X-Mailgun-Track-Opens': 'no',
'X-Mailgun-Variables': 'my_message_id: 123',
}
expected_output = [
('o:tag', 'Tag 1'),
('o:tag', 'Tag 2'),
('o:campaign', '1'),
('o:dkim', 'yes'),
('o:deliverytime', 'Thu, 13 Oct 2011 18:02:00 GMT'),
('o:testmode', 'yes'),
('o:tracking', 'yes'),
('o:tracking-clicks', 'htmlonly'),
('o:tracking-opens', 'no'),
('v:my-var', 'my_message_id: 123'),
]
check_output_value(mb, message, test_input, expected_output)