Debian Codegraph @

tests/test_imapserver_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
19 import pytest
20
21 from aioimaplib import extract_exists
22 from aioimaplib.aioimaplib import Command
23 from tests.server_fixture import with_server, login_user_async
24
25
26 @pytest.mark.asyncio()
27 async def test_append_too_long(with_server):
28 imap_client = await login_user_async('user@mail', 'pass')
29 assert 0 == extract_exists((await imap_client.examine('INBOX')))
30
31 message_bytes = b'do you see me ?'
32 imap_client.protocol.literal_data = message_bytes * 2
33
34 args = ['INBOX', '{%s}' % len(message_bytes)]
35 response = await imap_client.protocol.execute(
36 Command('APPEND', imap_client.protocol.new_tag(), *args, loop=asyncio.get_running_loop())
37 )
38 assert 'BAD' == response.result
39 assert b'expected CRLF but got' in response.lines[0]
40
41
42 @pytest.mark.asyncio()
43 async def test_append_too_short(with_server):
44 imap_client = await login_user_async('user@mail', 'pass')
45 assert 0 == extract_exists((await imap_client.examine('INBOX')))
46
47 message_bytes = b'do you see me ?' * 2
48 imap_client.protocol.literal_data = message_bytes[:5]
49
50 args = ['INBOX', '{%s}' % len(message_bytes)]
51 response = await imap_client.protocol.execute(
52 Command('APPEND', imap_client.protocol.new_tag(), *args, loop=asyncio.get_running_loop())
53 )
54 assert 'BAD' == response.result
55 assert b'expected 30 but was' in response.lines[0]