Skip to content

Commit f9d1b8b

Browse files
author
Rich Leland
committed
Add test for content_subtype
1 parent ccccbdb commit f9d1b8b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

sparkpost/django/message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def __init__(self, message):
3333
if message.subject:
3434
formatted['subject'] = message.subject
3535

36-
if message.content_subtype == 'html':
36+
if hasattr(message, 'template'):
37+
formatted['template'] = message.template
38+
elif message.content_subtype == 'html':
3739
formatted['html'] = message.body
3840
else:
3941
formatted['text'] = message.body
@@ -73,10 +75,8 @@ def __init__(self, message):
7375
'data': base64_encoded_content.decode('ascii'),
7476
'type': mimetype
7577
})
78+
7679
if hasattr(message, 'substitution_data'):
7780
formatted['substitution_data'] = message.substitution_data
7881

79-
if hasattr(message, 'template'):
80-
formatted['template'] = message.template
81-
8282
super(SparkPostMessage, self).__init__(formatted)

test/django/test_message.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,22 @@ def test_attachment_unicode():
108108
assert actual == expected
109109

110110

111+
def test_content_subtype():
112+
email_message = EmailMessage(
113+
114+
from_email='[email protected]',
115+
body='<p>Testing</p>'
116+
)
117+
email_message.content_subtype = 'html'
118+
actual = SparkPostMessage(email_message)
119+
expected = dict(
120+
recipients=['[email protected]'],
121+
from_email='[email protected]',
122+
html='<p>Testing</p>'
123+
)
124+
assert actual == expected
125+
126+
111127
def test_template():
112128
email_message = EmailMessage(
113129

0 commit comments

Comments
 (0)