Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_translate_keys_with_multiple_cc():
t = Transmissions('uri', 'key')
results = t._translate_keys(recipients=['primary@example.com'],
cc=['ccone@example.com', 'cctwo@example.com'])
assert results['recipients'] == [
{'address': {'email': 'primary@example.com'}},
{'address': {'email': 'ccone@example.com',
'header_to': 'primary@example.com'}},
{'address': {'email': 'cctwo@example.com',
'header_to': 'primary@example.com'}},
]
assert results['content']['headers'] == {
'CC': 'ccone@example.com,cctwo@example.com'
}
def test_cc_with_sub_data():
t = Transmissions('uri', 'key')
results = t._translate_keys(
recipients=[{
'address': {'email': 'primary@example.com'},
'substitution_data': {'fake': 'data'}
}],
cc=['ccone@example.com']
)
assert results['recipients'] == [
{
'address': {'email': 'primary@example.com'},
'substitution_data': {'fake': 'data'}
},
{
'address': {
'email': 'ccone@example.com',
'header_to': 'primary@example.com'
def test_translate_keys_with_recips():
t = Transmissions('uri', 'key')
results = t._translate_keys(recipients=['test',
{'key': 'value'}, 'foobar'])
assert results['recipients'] == [{'address': {'email': 'test'}},
{'key': 'value'},
{'address': {'email': 'foobar'}}]
def test_format_header_to():
t = Transmissions('uri', 'key')
formatted = t._format_header_to(recipient={
'address': {'email': 'primary@example.com'}
})
assert formatted == 'primary@example.com'
formatted = t._format_header_to(recipient={
'address': {'name': 'Testing', 'email': 'primary@example.com'}
})
assert formatted == '"Testing" '
def test_translate_keys_with_bcc():
t = Transmissions('uri', 'key')
results = t._translate_keys(recipients=['primary@example.com'],
bcc=['bccone@example.com'])
assert results['recipients'] == [
{'address': {'email': 'primary@example.com'}},
{'address': {'email': 'bccone@example.com',
'header_to': 'primary@example.com'}},
]
def test_translate_keys_for_email_parsing():
t = Transmissions('uri', 'key')
results = t._translate_keys(recipients=['hansel@example.com',
'Gretel '])
assert results['recipients'] == [
{'address': {'email': 'hansel@example.com'}},
{'address': {'name': 'Gretel', 'email': 'gretel@example.com'}}
]
def test_translate_keys_with_cc():
t = Transmissions('uri', 'key')
results = t._translate_keys(recipients=['primary@example.com'],
cc=['ccone@example.com'])
assert results['recipients'] == [
{'address': {'email': 'primary@example.com'}},
{'address': {'email': 'ccone@example.com',
'header_to': 'primary@example.com'}},
]
assert results['content']['headers'] == {
'CC': 'ccone@example.com'
}
def test_translate_keys_with_inline_css():
t = Transmissions('uri', 'key')
results = t._translate_keys(inline_css=True)
assert results['options'].get('inline_css') is True
def test_translate_keys_with_email_rfc822():
t = Transmissions('uri', 'key')
# Build data using implicit cat, as max line length is enforced
eml = (
'To: wilma \n',
'From: fred \n',
'Subject: Bedrock declaration\n',
'MIME-Version: 1.0\n',
'Content-Type: text/plain; charset=utf-8; format=flowed\n',
'Content-Transfer-Encoding: 7bit\nContent-Language: en-GB\n',
'\n',
'When in the Course of human events we yell yabba dabba doo.',
)
# Just a selection. Don't test attribs with irregular naming
non_rfc822_attrs = {
'headers': 'foo',
def test_exceptions_for_recipients():
t = Transmissions('uri', 'key')
with pytest.raises(SparkPostException):
t._translate_keys(recipients='test')