Skip to content

Commit

Permalink
#176 but only the if block
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Zamora committed Aug 10, 2018
1 parent e4cf55d commit a55235b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
3 changes: 3 additions & 0 deletions sparkpost/django/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def __init__(self, message):
if hasattr(message, 'campaign'):
formatted['campaign'] = message.campaign

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

if message.extra_headers:
formatted['custom_headers'] = message.extra_headers
if 'X-MSYS-API' in message.extra_headers:
Expand Down
49 changes: 41 additions & 8 deletions test/django/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,67 @@ def test_campaign():
assert actual == expected


def test_metadata():
email_message = EmailMessage(
to=[
{
'address': '[email protected]',
'metadata': {
'key': 'value'
}
}
],
from_email='[email protected]'
)
email_message.template = 'template-id'
email_message.metadata = {'key2': 'value2'}
actual = SparkPostMessage(email_message)

expected = dict(
recipients=[
{
'address': '[email protected]',
'metadata': {
'key': 'value'
}
}
],
from_email='[email protected]',
template='template-id',
metadata={'key2': 'value2'}
)

assert actual == expected


def test_substitution_data():
email_message = EmailMessage(
to=[
{
"address": "[email protected]",
"substitution_data": {
"key": "value"
'address': '[email protected]',
'substitution_data': {
'key': 'value'
}
}
],
from_email='[email protected]'
)
email_message.template = 'template-id'
email_message.substitution_data = {"key2": "value2"}
email_message.substitution_data = {'key2': 'value2'}
actual = SparkPostMessage(email_message)

expected = dict(
recipients=[
{
"address": "[email protected]",
"substitution_data": {
"key": "value"
'address': '[email protected]',
'substitution_data': {
'key': 'value'
}
}
],
from_email='[email protected]',
template='template-id',
substitution_data={"key2": "value2"}
substitution_data={'key2': 'value2'}
)

assert actual == expected
Expand Down

0 comments on commit a55235b

Please sign in to comment.