def test_msgloader():

    data = {'charset': 'utf-8',
            'subject': 'Что-то по-русски',
            'mail_from': ('Максим Иванов', '*****@*****.**'),
            'mail_to': ('Полина Сергеева', '*****@*****.**'),
            'html': '<h1>Привет!</h1><p>В первых строках...',
            'text': 'Привет!\nВ первых строках...',
            'headers': {'X-Mailer': 'python-emails',
                        'Sender': '웃'},
            'attachments': [{'data': 'X', 'filename': 'Event.ics'},
                            {'data': 'Y', 'filename': 'Map.png', 'content_disposition': 'inline'},],
            'message_id': 'message_id'}

    source_message = emails.Message(**data)
    message = emails.loader.from_rfc822(source_message.as_string(), parse_headers=True)

    loader = message._loader

    assert loader.html == data['html']
    assert loader.text == data['text']

    assert 'Event.ics' in loader.list_files()
    assert loader.content('Event.ics') == 'X'

    # check file search by content-id
    map_cid = "cid:%s" % source_message.attachments['Map.png'].content_id
    assert loader.content(map_cid) == 'Y'

    assert message.subject == data['subject']
    print(message._headers)
    assert message._headers['sender'] == '웃'

    assert message.as_string()
def test_msgloader():

    data = {
        'charset':
        'utf-8',
        'subject':
        'Что-то по-русски',
        'mail_from': ('Максим Иванов', '*****@*****.**'),
        'mail_to': [('Полина Сергеева', '*****@*****.**'),
                    ('test', '*****@*****.**')],
        'html':
        '<h1>Привет!</h1><p>В первых строках...',
        'text':
        'Привет!\nВ первых строках...',
        'headers': {
            'X-Mailer': 'python-emails',
            'Sender': '웃'
        },
        'attachments': [
            {
                'data': 'X',
                'filename': 'Event.ics'
            },
            {
                'data': 'Y',
                'filename': 'Map.png',
                'content_disposition': 'inline'
            },
        ],
        'message_id':
        'message_id'
    }

    source_message = emails.Message(**data)
    message = emails.loader.from_rfc822(source_message.as_string(),
                                        parse_headers=True)

    loader = message._loader

    assert loader.html == data['html']
    assert loader.text == data['text']

    assert 'Event.ics' in loader.list_files()
    assert loader.content('Event.ics') == 'X'

    # check file search by content-id
    map_cid = "cid:%s" % source_message.attachments['Map.png'].content_id
    assert loader.content(map_cid) == 'Y'

    assert message.mail_to == data['mail_to']
    assert message.subject == data['subject']
    print(message._headers)
    assert message._headers['sender'] == '웃'

    assert message.as_string()
示例#3
0
def test_local_store1():
    for loader in _get_loaders():
        print(loader)
        assert isinstance(loader.content('index.html'), text_type)
        assert isinstance(loader['index.html'], bytes)
        assert '<table' in loader.content('index.html')
        with pytest.raises(FileNotFound):
            loader.get_file('-nonexistent-file')
        with pytest.raises(FileNotFound):
            loader.find_index_file('-nonexistent-file')
        assert loader.find_index_html()
        assert not loader.find_index_text()
        files_list = list(loader.list_files())
        assert 'images/arrow.png' in files_list
        assert len(files_list) in [15, 16]
        # TODO: remove directories from zip loader list_files results
        assert loader.get_file('./images/img01.jpg') == loader.get_file('images/img01.jpg')
示例#4
0
def test_local_store1():
    for loader in _get_loaders():
        print(loader)
        assert isinstance(loader.content('index.html'), text_type)
        assert isinstance(loader['index.html'], bytes)
        assert '<table' in loader.content('index.html')
        with pytest.raises(FileNotFound):
            loader.get_file('-nonexistent-file')
        with pytest.raises(FileNotFound):
            loader.find_index_file('-nonexistent-file')
        assert loader.find_index_html()
        assert not loader.find_index_text()
        files_list = list(loader.list_files())
        assert 'images/arrow.png' in files_list
        assert len(files_list) in [15, 16]
        # TODO: remove directories from zip loader list_files results
        assert loader.get_file('./images/img01.jpg') == loader.get_file('images/img01.jpg')