Exemplo n.º 1
0
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_translate_keys_for_from_email():
    t = Transmissions('uri', 'key')
    results = t._translate_keys(from_email='Testing <*****@*****.**>')
    assert results['content']['from'] == {
        'name': 'Testing',
        'email': '*****@*****.**'
    }
Exemplo n.º 3
0
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'
        }
    }]
Exemplo n.º 4
0
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]'
    }
Exemplo n.º 5
0
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_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'}}]
Exemplo n.º 7
0
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': '*****@*****.**'
    }
Exemplo n.º 8
0
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': '*****@*****.**'}}
    ]
Exemplo n.º 9
0
def test_translate_keys_with_unicode_recips():
    t = Transmissions('uri', 'key')
    results = t._translate_keys(recipients=[u'*****@*****.**',
                                            '*****@*****.**'])
    assert results['recipients'] == [
        {'address': {'email': '*****@*****.**'}},
        {'address': {'email': '*****@*****.**'}}
    ]
Exemplo n.º 10
0
def test_translate_keys_with_unicode_recips():
    t = Transmissions('uri', 'key')
    results = t._translate_keys(recipients=[u'*****@*****.**',
                                            '*****@*****.**'])
    assert results['recipients'] == [
        {'address': {'email': '*****@*****.**'}},
        {'address': {'email': '*****@*****.**'}}
    ]
Exemplo n.º 11
0
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': '*****@*****.**'}}
    ]
Exemplo n.º 12
0
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': '*****@*****.**'}},
    ]
Exemplo n.º 13
0
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': '*****@*****.**'}},
    ]
Exemplo n.º 14
0
def test_format_header_to():
    t = Transmissions('uri', 'key')
    formatted = t._format_header_to(recipient={
        'address': {'email': '*****@*****.**'}
    })
    assert formatted == '*****@*****.**'

    formatted = t._format_header_to(recipient={
        'address': {'name': 'Testing', 'email': '*****@*****.**'}
    })
    assert formatted == '"Testing" <*****@*****.**>'
Exemplo n.º 15
0
def test_format_header_to():
    t = Transmissions('uri', 'key')
    formatted = t._format_header_to(recipient={
        'address': {'email': '*****@*****.**'}
    })
    assert formatted == '*****@*****.**'

    formatted = t._format_header_to(recipient={
        'address': {'name': 'Testing', 'email': '*****@*****.**'}
    })
    assert formatted == '"Testing" <*****@*****.**>'
Exemplo n.º 16
0
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]'
    }
Exemplo n.º 17
0
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'}
        }
    ]
Exemplo n.º 18
0
def test_exceptions_for_recipients():
    t = Transmissions('uri', 'key')
    with pytest.raises(SparkPostException):
        t._translate_keys(recipients='test')
Exemplo n.º 19
0
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'}
Exemplo n.º 20
0
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
Exemplo n.º 21
0
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'}
Exemplo n.º 22
0
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'}
Exemplo n.º 23
0
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
Exemplo n.º 24
0
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'}