Debian Codegraph @

tests/test_acceptance_aioimaplib.py

raw
1 # -*- coding: utf-8 -*-
2 # aioimaplib : an IMAPrev4 lib using python asyncio
3 # Copyright (C) 2016 Bruno Thomas
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 import asyncio
18 import email
19
20 import os
21
22 import pytest
23
24 from aioimaplib.imap_testing_server import Mail
25 from tests.server_fixture import with_server, login_user_async
26
27
28 @pytest.mark.asyncio()
29 async def test_file_with_attachment(with_server):
30 with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/test_attachment.eml'), mode='br') as msg:
31 imap_client = await login_user_async('user@mail', 'pass', select=True)
32 mail = Mail(email.message_from_binary_file(msg))
33
34 with_server.receive(mail, imap_user='user@mail')
35
36 result, data = await imap_client.fetch('1', '(RFC822)')
37
38 assert 'OK' == result
39 assert [b'1 FETCH (RFC822 {418898}', mail.as_bytes(), b')', b'FETCH completed.'] == data