-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jose Zamora
committed
Oct 3, 2019
1 parent
47d9c34
commit 0805998
Showing
2 changed files
with
104 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,69 +186,117 @@ def test_campaign(): | |
assert actual == expected | ||
|
||
|
||
def test_metadata(): | ||
def test_recipient_attributes(): | ||
email_message = EmailMessage( | ||
to=[ | ||
{ | ||
'address': '[email protected]', | ||
'substitution_data': { | ||
'sub': 'value' | ||
}, | ||
'metadata': { | ||
'key': 'value' | ||
} | ||
'meta': 'value' | ||
}, | ||
'tags': ['tag1'] | ||
} | ||
], | ||
from_email='[email protected]' | ||
) | ||
|
||
email_message.template = 'template-id' | ||
email_message.metadata = {'key2': 'value2'} | ||
actual = SparkPostMessage(email_message) | ||
|
||
expected = dict( | ||
recipients=[ | ||
{ | ||
'address': '[email protected]', | ||
'substitution_data': { | ||
'sub': 'value' | ||
}, | ||
'metadata': { | ||
'key': 'value' | ||
} | ||
'meta': 'value' | ||
}, | ||
'tags': ['tag1'] | ||
} | ||
], | ||
from_email='[email protected]', | ||
template='template-id' | ||
) | ||
|
||
assert actual == expected | ||
|
||
|
||
def test_pass_through_attr(): | ||
|
||
pass_through_attributes = { | ||
'substitution_data': {'sub': 'vale'}, | ||
'metadata': {'meta': 'value'}, | ||
'description': 'a description', | ||
'return_path': '[email protected]', | ||
'ip_pool': 'pool-id', | ||
'inline_css': True, | ||
'transactional': True, | ||
'start_time': 'YYYY-MM-DDTHH:MM:SS+-HH:MM', | ||
'skip_suppression': True | ||
} | ||
|
||
email_message = EmailMessage( | ||
to=[{'address': '[email protected]'}], | ||
from_email='[email protected]' | ||
) | ||
email_message.template = 'template-id' | ||
|
||
for key, value in pass_through_attributes.items(): | ||
setattr(email_message, key, value) | ||
|
||
actual = SparkPostMessage(email_message) | ||
|
||
expected = dict( | ||
recipients=[{'address': '[email protected]'}], | ||
from_email='[email protected]', | ||
template='template-id', | ||
metadata={'key2': 'value2'} | ||
) | ||
|
||
for key, value in pass_through_attributes.items(): | ||
expected[key] = value | ||
|
||
assert actual == expected | ||
|
||
|
||
def test_substitution_data(): | ||
def test_transform_attr(): | ||
|
||
attributes_to_transform = { | ||
'sandbox': True, | ||
'open_tracking': False, | ||
'click_tracking': False, | ||
} | ||
|
||
email_message = EmailMessage( | ||
to=[ | ||
{ | ||
'address': '[email protected]', | ||
'substitution_data': { | ||
'key': 'value' | ||
} | ||
} | ||
], | ||
to=[{'address': '[email protected]'}], | ||
from_email='[email protected]' | ||
) | ||
email_message.template = 'template-id' | ||
email_message.substitution_data = {'key2': 'value2'} | ||
|
||
for key, value in attributes_to_transform.items(): | ||
setattr(email_message, key, value) | ||
|
||
actual = SparkPostMessage(email_message) | ||
|
||
expected = dict( | ||
recipients=[ | ||
{ | ||
'address': '[email protected]', | ||
'substitution_data': { | ||
'key': 'value' | ||
} | ||
} | ||
], | ||
recipients=[{'address': '[email protected]'}], | ||
from_email='[email protected]', | ||
template='template-id', | ||
substitution_data={'key2': 'value2'} | ||
) | ||
|
||
transformed_attributes = { | ||
'use_sandbox': True, | ||
'track_opens': False, | ||
'track_clicks': False | ||
} | ||
|
||
for key, value in transformed_attributes.items(): | ||
expected[key] = value | ||
|
||
assert actual == expected | ||
|
||
|
||
|