diff --git a/aioimaplib/imapserver.py b/aioimaplib/imap_testing_server.py similarity index 99% rename from aioimaplib/imapserver.py rename to aioimaplib/imap_testing_server.py index 9ab5c5e..6fe8c3c 100644 --- a/aioimaplib/imapserver.py +++ b/aioimaplib/imap_testing_server.py @@ -806,8 +806,8 @@ async def async_main(**kwargs): def main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, - prog='imapserver', - description='Small python asyncio IMAP testing server.', + prog='imap-testing-server', + description='Small python asyncio IMAP testing server from aioimaplib.', epilog='') parser.add_argument('--port', help='tcp port of the server', default=1143) parser.add_argument('--host', help='host of the server', default='127.0.0.1') diff --git a/pyproject.toml b/pyproject.toml index 766b231..8bcd431 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,4 +43,4 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.poetry.scripts] -imapserver = "aioimaplib.imapserver:main" \ No newline at end of file +imap-testing-server = "aioimaplib.imap_testing_server:main" \ No newline at end of file diff --git a/tests/server_fixture.py b/tests/server_fixture.py index 369a05b..f429efb 100644 --- a/tests/server_fixture.py +++ b/tests/server_fixture.py @@ -9,7 +9,7 @@ import pytest from aioimaplib import aioimaplib -from aioimaplib.imapserver import MockImapServer +from aioimaplib.imap_testing_server import MockImapServer from tests.ssl_cert import create_temp_self_signed_cert diff --git a/tests/test_acceptance_aioimaplib.py b/tests/test_acceptance_aioimaplib.py index 6571798..e457cb2 100644 --- a/tests/test_acceptance_aioimaplib.py +++ b/tests/test_acceptance_aioimaplib.py @@ -21,7 +21,7 @@ import pytest -from aioimaplib.imapserver import Mail +from aioimaplib.imap_testing_server import Mail from tests.server_fixture import with_server, login_user_async diff --git a/tests/test_aioimaplib.py b/tests/test_aioimaplib.py index c2733fd..07014c6 100644 --- a/tests/test_aioimaplib.py +++ b/tests/test_aioimaplib.py @@ -26,8 +26,8 @@ from aioimaplib import aioimaplib, extract_exists, STOP_WAIT_SERVER_PUSH, FetchCommand, IdleCommand from aioimaplib.aioimaplib import Commands, IMAP4ClientProtocol, Command, Abort -from aioimaplib import imapserver -from aioimaplib.imapserver import Mail +from aioimaplib import imap_testing_server +from aioimaplib.imap_testing_server import Mail from tests.server_fixture import with_ssl_server, with_ssl, with_server, login_user_async, create_server aioimaplib.log.setLevel(logging.WARNING) @@ -610,11 +610,11 @@ async def test_check(with_server): @pytest.mark.asyncio() async def test_close(with_server): imap_client = await login_user_async('user', 'pass', select=True) - assert imapserver.SELECTED == with_server.get_connection('user').state + assert imap_testing_server.SELECTED == with_server.get_connection('user').state assert ('OK', [b'CLOSE completed.']) == (await imap_client.close()) - assert imapserver.AUTH == with_server.get_connection('user').state + assert imap_testing_server.AUTH == with_server.get_connection('user').state @pytest.mark.asyncio() diff --git a/tests/test_aioimaplib_capabilities.py b/tests/test_aioimaplib_capabilities.py index 10cc294..a532198 100644 --- a/tests/test_aioimaplib_capabilities.py +++ b/tests/test_aioimaplib_capabilities.py @@ -5,7 +5,7 @@ from aioimaplib import aioimaplib from aioimaplib.aioimaplib import Abort -from aioimaplib.imapserver import ImapProtocol, ServerState, MockImapServer +from aioimaplib.imap_testing_server import ImapProtocol, ServerState, MockImapServer from tests.server_fixture import with_server, login_user_async, main_test aioimaplib.log.setLevel(logging.WARNING) diff --git a/tests/test_aioimaplib_clocked.py b/tests/test_aioimaplib_clocked.py index bd2d2ab..c08e9ce 100644 --- a/tests/test_aioimaplib_clocked.py +++ b/tests/test_aioimaplib_clocked.py @@ -3,7 +3,7 @@ import pytest from aioimaplib import Command, CommandTimeout, STOP_WAIT_SERVER_PUSH, AioImapException, Response -from aioimaplib import imapserver +from aioimaplib.imap_testing_server import ImapProtocol from tests.server_fixture import with_server, login_user_async, advance_time @@ -152,7 +152,7 @@ async def test_idle_start__exits_queueget_with_keepalive_without_timeout_error(e imap_client = await login_user_async('user', 'pass', select=True, loop=event_loop) # Idle long enough for the server to issue a keep-alive - server_idle_timeout = imapserver.ImapProtocol.IDLE_STILL_HERE_PERIOD_SECONDS + server_idle_timeout = ImapProtocol.IDLE_STILL_HERE_PERIOD_SECONDS idle_timeout = server_idle_timeout + 1 idle = await imap_client.idle_start(idle_timeout) diff --git a/tests/test_imapserver.py b/tests/test_imapserver.py index 47695e8..b875951 100644 --- a/tests/test_imapserver.py +++ b/tests/test_imapserver.py @@ -26,8 +26,7 @@ import pytz import sys -from aioimaplib import imapserver -from aioimaplib.imapserver import ServerState, Mail, MockImapServer, ImapProtocol, InvalidUidSet +from aioimaplib.imap_testing_server import ServerState, Mail, MockImapServer, ImapProtocol, InvalidUidSet import pytest @@ -35,54 +34,54 @@ class TestMailToString(unittest.TestCase): def test_message_date_string(self): now = pytz.timezone('Europe/Paris').localize(datetime(2016, 2, 2, 12, 13, 14, 151)) - mail = imapserver.Mail.create(['user'], date=now) + mail = Mail.create(['user'], date=now) assert mail.email.get('Date') == 'Tue, 02 Feb 2016 12:13:14 +0100' def test_message_default_date_string_is_utc(self): - mail = imapserver.Mail.create(['user']) + mail = Mail.create(['user']) assert mail.email.get('Date').endswith('+0000') def test_message_title_string_without_accents_isnot_encoded(self): now = pytz.timezone('Europe/Paris').localize(datetime(2016, 2, 2, 12, 13, 14, 151)) - mail = imapserver.Mail.create(['user'], subject='subject', date=now) + mail = Mail.create(['user'], subject='subject', date=now) assert mail.email.get('Subject') == 'subject' def test_message_title_string_with_accents_is_base64encoded(self): - mail = imapserver.Mail.create(['user'], subject='Classé ?') + mail = Mail.create(['user'], subject='Classé ?') assert '=?utf-8?b?Q2xhc3PDqSA/?=' in mail.as_string() def test_message_quoted_printable(self): - mail = imapserver.Mail.create(['user'], content='Bonjour à vous', quoted_printable=True) + mail = Mail.create(['user'], content='Bonjour à vous', quoted_printable=True) assert 'Bonjour =C3=A0 vous' in mail.as_string(), '"=C3=A0" not found in %s' % mail.as_string() def test_message_not_quoted_printable(self): - mail = imapserver.Mail.create(['user'], subject='élo ?', content='Bonjour à vous').as_bytes() + mail = Mail.create(['user'], subject='élo ?', content='Bonjour à vous').as_bytes() m = email.message_from_bytes(mail) assert 'Bonjour à vous' == m.get_payload(decode=True).decode() def test_header_encode_to(self): - mail = imapserver.Mail.create(['Zébulon Durand '], mail_from='from@mail.fr', subject='subject') + mail = Mail.create(['Zébulon Durand '], mail_from='from@mail.fr', subject='subject') assert '=?utf-8?q?Z=C3=A9bulon_Durand_=3Czeb=40zebulon=2Eio=3E?=' in mail.as_string(), 'expected string not found in :%s\n' % mail.as_string() def test_mail_from(self): - mail = imapserver.Mail.create(['user'], subject='subject') + mail = Mail.create(['user'], subject='subject') assert mail.email.get('From') == '' - mail = imapserver.Mail.create(['user'], mail_from='', subject='subject') + mail = Mail.create(['user'], mail_from='', subject='subject') assert mail.email.get('From') == '' - mail = imapserver.Mail.create(['user'], mail_from='test@test', subject='subject') + mail = Mail.create(['user'], mail_from='test@test', subject='subject') assert mail.email.get('From') == '' - mail = imapserver.Mail.create(['user'], mail_from='Test ', subject='subject') + mail = Mail.create(['user'], mail_from='Test ', subject='subject') assert mail.email.get('From') == 'Test ' def test_build_sequence_range(self): diff --git a/tests/test_imapserver_imaplib.py b/tests/test_imapserver_imaplib.py index 68c050f..d4f1199 100644 --- a/tests/test_imapserver_imaplib.py +++ b/tests/test_imapserver_imaplib.py @@ -24,8 +24,7 @@ import pytest from pytz import utc -from aioimaplib import imapserver -from aioimaplib.imapserver import Mail +from aioimaplib.imap_testing_server import Mail, AUTH, SELECTED, LOGOUT from tests.server_fixture import with_server, login_user, with_ssl, with_ssl_server @@ -47,7 +46,7 @@ async def test_server_login(with_server): assert 'OK' == result assert [b'LOGIN completed'] == data - assert imapserver.AUTH == with_server.get_connection('user').state + assert AUTH == with_server.get_connection('user').state @pytest.mark.asyncio @@ -59,7 +58,7 @@ async def test_select_no_messages_in_mailbox(with_server): assert 'OK' == result assert [b'0'] == data - assert imapserver.SELECTED == with_server.get_connection('user@mail').state + assert SELECTED == with_server.get_connection('user@mail').state @pytest.mark.asyncio @@ -95,7 +94,7 @@ async def test_examine_no_messages_in_mailbox(with_server): assert ('OK', [b'0']) == (await asyncio.wait_for( asyncio.get_running_loop().run_in_executor(None, functools.partial(imap_client.select, readonly=True)), 1)) - assert imapserver.AUTH == with_server.get_connection('user').state + assert AUTH == with_server.get_connection('user').state @pytest.mark.asyncio @@ -383,12 +382,12 @@ async def test_subscribe_unsubscribe_lsub(with_server): @pytest.mark.asyncio async def test_close(with_server): imap_client = await login_user('user', 'pass', select=True) - assert imapserver.SELECTED == with_server.get_connection('user').state + assert SELECTED == with_server.get_connection('user').state assert ('OK', [b'CLOSE completed.']) == \ (await asyncio.wait_for(asyncio.get_running_loop().run_in_executor(None, imap_client.close), 1)) - assert imapserver.AUTH == with_server.get_connection('user').state + assert AUTH == with_server.get_connection('user').state @pytest.mark.asyncio @@ -480,7 +479,7 @@ async def test_logout(with_server): assert 'BYE' == result # uhh ? assert [b'Logging out'] == data - assert imapserver.LOGOUT == with_server.get_connection('user').state + assert LOGOUT == with_server.get_connection('user').state @pytest.mark.asyncio diff --git a/tests/test_imapserver_imaplib2.py b/tests/test_imapserver_imaplib2.py index 1bfaf28..76b47ad 100644 --- a/tests/test_imapserver_imaplib2.py +++ b/tests/test_imapserver_imaplib2.py @@ -21,8 +21,7 @@ from imaplib2 import imaplib2 from mock import Mock -from aioimaplib import imapserver -from aioimaplib.imapserver import Mail +from aioimaplib.imap_testing_server import Mail, IDLE, SELECTED from tests.server_fixture import with_server, login_user import pytest @@ -33,12 +32,12 @@ async def test_idle(with_server): imap_client = await login_user('user', 'pass', select=True, lib=imaplib2.IMAP4) idle_callback = Mock() asyncio.get_running_loop().run_in_executor(None, functools.partial(imap_client.idle, callback=idle_callback)) - await asyncio.wait_for(with_server.get_connection('user').wait(imapserver.IDLE), 1) + await asyncio.wait_for(with_server.get_connection('user').wait(IDLE), 1) asyncio.get_running_loop().run_in_executor(None, functools.partial(with_server.receive, Mail.create(to=['user'], mail_from='me', subject='hello'))) - await asyncio.wait_for(with_server.get_connection('user').wait(imapserver.SELECTED), 5) + await asyncio.wait_for(with_server.get_connection('user').wait(SELECTED), 5) time.sleep(0.2) # eurk hate sleeps but I don't know how to wait for the lib to receive end of IDLE idle_callback.assert_called_once()