Skip to content

Commit

Permalink
Add test for content_subtype
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Leland committed Apr 19, 2016
1 parent ccccbdb commit f9d1b8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sparkpost/django/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def __init__(self, message):
if message.subject:
formatted['subject'] = message.subject

if message.content_subtype == 'html':
if hasattr(message, 'template'):
formatted['template'] = message.template
elif message.content_subtype == 'html':
formatted['html'] = message.body
else:
formatted['text'] = message.body
Expand Down Expand Up @@ -73,10 +75,8 @@ def __init__(self, message):
'data': base64_encoded_content.decode('ascii'),
'type': mimetype
})

if hasattr(message, 'substitution_data'):
formatted['substitution_data'] = message.substitution_data

if hasattr(message, 'template'):
formatted['template'] = message.template

super(SparkPostMessage, self).__init__(formatted)
16 changes: 16 additions & 0 deletions test/django/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ def test_attachment_unicode():
assert actual == expected


def test_content_subtype():
email_message = EmailMessage(
to=['to@example.com'],
from_email='test@from.com',
body='<p>Testing</p>'
)
email_message.content_subtype = 'html'
actual = SparkPostMessage(email_message)
expected = dict(
recipients=['to@example.com'],
from_email='test@from.com',
html='<p>Testing</p>'
)
assert actual == expected


def test_template():
email_message = EmailMessage(
to=['to@example.com'],
Expand Down

0 comments on commit f9d1b8b

Please sign in to comment.