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_cc_with_sub_data(): t = Transmissions('uri', 'key') results = t._translate_keys(recipients=[{ 'address': { 'email': '*****@*****.**' }, 'substitution_data': { 'fake': 'data' } }], cc=['*****@*****.**']) assert results['recipients'] == [{ 'address': { 'email': '*****@*****.**' }, 'substitution_data': { 'fake': 'data' } }, { 'address': { 'email': '*****@*****.**', 'header_to': '*****@*****.**' }, 'substitution_data': { 'fake': 'data' } }]
def test_translate_keys_for_from_email(): t = Transmissions('uri', 'key') results = t._translate_keys(from_email='Testing <*****@*****.**>') assert results['content']['from'] == { 'name': 'Testing', 'email': '*****@*****.**' }
def test_translate_keys_with_multiple_cc(): t = Transmissions('uri', 'key') results = t._translate_keys(recipients=['*****@*****.**'], cc=['*****@*****.**', '*****@*****.**']) assert results['recipients'] == [ { 'address': { 'email': '*****@*****.**' } }, { 'address': { 'email': '*****@*****.**', 'header_to': '*****@*****.**' } }, { 'address': { 'email': '*****@*****.**', 'header_to': '*****@*****.**' } }, ] assert results['content']['headers'] == { 'CC': '[email protected],[email protected]' }
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', 'reply_to': 'foo', 'subject': 'foo', 'html': 'foo', 'text': 'foo', } # Demonstrate that email_rfc822 overrides other content attributes test_content = {'email_rfc822': eml} test_content.update(non_rfc822_attrs) results = t._translate_keys(**test_content) for i in non_rfc822_attrs: assert results['content'].get(i) is None assert results['content'].get('email_rfc822') is not None
def test_translate_keys_for_email_parsing(): t = Transmissions('uri', 'key') results = t._translate_keys(recipients=['*****@*****.**', 'Gretel <*****@*****.**>']) assert results['recipients'] == [ {'address': {'email': '*****@*****.**'}}, {'address': {'name': 'Gretel', 'email': '*****@*****.**'}} ]
def test_translate_keys_with_unicode_recips(): t = Transmissions('uri', 'key') results = t._translate_keys(recipients=[u'*****@*****.**', '*****@*****.**']) assert results['recipients'] == [ {'address': {'email': '*****@*****.**'}}, {'address': {'email': '*****@*****.**'}} ]
def test_translate_keys_with_bcc(): t = Transmissions('uri', 'key') results = t._translate_keys(recipients=['*****@*****.**'], bcc=['*****@*****.**']) assert results['recipients'] == [ {'address': {'email': '*****@*****.**'}}, {'address': {'email': '*****@*****.**', 'header_to': '*****@*****.**'}}, ]
def test_translate_keys_with_multiple_cc(): t = Transmissions('uri', 'key') results = t._translate_keys(recipients=['*****@*****.**'], cc=['*****@*****.**', '*****@*****.**']) assert results['recipients'] == [ {'address': {'email': '*****@*****.**'}}, {'address': {'email': '*****@*****.**', 'header_to': '*****@*****.**'}}, {'address': {'email': '*****@*****.**', 'header_to': '*****@*****.**'}}, ] assert results['content']['headers'] == { 'CC': '[email protected],[email protected]' }
def test_cc_with_sub_data(): t = Transmissions('uri', 'key') results = t._translate_keys( recipients=[{ 'address': {'email': '*****@*****.**'}, 'substitution_data': {'fake': 'data'} }], cc=['*****@*****.**'] ) assert results['recipients'] == [ { 'address': {'email': '*****@*****.**'}, 'substitution_data': {'fake': 'data'} }, { 'address': { 'email': '*****@*****.**', 'header_to': '*****@*****.**' }, 'substitution_data': {'fake': 'data'} } ]
def test_exceptions_for_recipients(): t = Transmissions('uri', 'key') with pytest.raises(SparkPostException): t._translate_keys(recipients='test')
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_list(): t = Transmissions('uri', 'key') results = t._translate_keys(recipient_list='test') assert results['return_path'] == '*****@*****.**' assert results['content']['use_draft_template'] is False assert results['recipients'] == {'list_id': 'test'}
def test_translate_keys_with_list(): t = Transmissions('uri', 'key') results = t._translate_keys(recipient_list='test') assert 'use_draft_template' not in results['content'] assert 'headers' not in results['content'] assert results['recipients'] == {'list_id': 'test'}
def test_translate_keys_with_list(): t = Transmissions('uri', 'key') results = t._translate_keys(recipient_list='test') assert results['content']['use_draft_template'] is False assert isinstance(results['content']['headers'], dict) assert results['recipients'] == {'list_id': 'test'}