From 9aa8bc953a77d5af77a0d719f81272d2ad79a043 Mon Sep 17 00:00:00 2001 From: "v.kaukin" Date: Wed, 22 Apr 2020 11:45:23 +0500 Subject: [PATCH] +outlook test box, improve flag test --- tests/test_actions.py | 4 ++-- tests/test_connection.py | 6 +++--- tests/test_folders.py | 12 ++++-------- tests/test_message.py | 7 ++++++- tests/utils.py | 28 +++++++++++++--------------- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/tests/test_actions.py b/tests/test_actions.py index 294b7ae..336bb4a 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -1,7 +1,7 @@ import unittest import imap_tools -from tests.utils import MailboxTestCase, test_mailbox_name_set, get_test_mailbox +from tests.utils import MailboxTestCase, TEST_MAILBOX_NAME_SET, get_test_mailbox class ActionTest(MailboxTestCase): @@ -10,7 +10,7 @@ class ActionTest(MailboxTestCase): @classmethod def setUpClass(cls): # clear temp folders - for test_mailbox_name in test_mailbox_name_set: + for test_mailbox_name in TEST_MAILBOX_NAME_SET: mailbox = get_test_mailbox(test_mailbox_name) mailbox.folder.set(mailbox.folder_test_temp1) for_del_1 = [msg.uid for msg in mailbox.fetch()] diff --git a/tests/test_connection.py b/tests/test_connection.py index 62d13fa..a5d6907 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1,13 +1,13 @@ import unittest from imap_tools import MailBox -from tests.utils import get_test_mailbox_config, test_mailbox_name_set +from tests.utils import get_test_mailbox_config, TEST_MAILBOX_NAME_SET class ConnectionTest(unittest.TestCase): def test_connection(self): # simple - for test_mailbox_name in test_mailbox_name_set: + for test_mailbox_name in TEST_MAILBOX_NAME_SET: config = get_test_mailbox_config(test_mailbox_name) mailbox = MailBox(config['host']) self.assertIs(type(mailbox), MailBox) @@ -16,7 +16,7 @@ def test_connection(self): logout_result = mailbox.logout() self.assertEqual(logout_result[0], 'BYE') # with - for test_mailbox_name in test_mailbox_name_set: + for test_mailbox_name in TEST_MAILBOX_NAME_SET: config = get_test_mailbox_config(test_mailbox_name) with MailBox(config['host']).login(config['email'], config['password']) as mailbox: self.assertIs(type(mailbox), MailBox) diff --git a/tests/test_folders.py b/tests/test_folders.py index 1ce3a89..1bac15d 100644 --- a/tests/test_folders.py +++ b/tests/test_folders.py @@ -1,13 +1,13 @@ import unittest -from tests.utils import MailboxTestCase, test_mailbox_name_set, get_test_mailbox +from tests.utils import MailboxTestCase, TEST_MAILBOX_NAME_SET, get_test_mailbox class FoldersTest(MailboxTestCase): @classmethod def setUpClass(cls): # delete temp new folders - for test_mailbox_name in test_mailbox_name_set: + for test_mailbox_name in TEST_MAILBOX_NAME_SET: mailbox = get_test_mailbox(test_mailbox_name) for del_folder in (mailbox.folder_test_new, mailbox.folder_test_new1): if mailbox.folder.exists(del_folder): @@ -15,14 +15,10 @@ def setUpClass(cls): def test_folders(self): for mailbox_name, mailbox in self.mailbox_set.items(): - if mailbox_name == 'MAIL_RU': - continue # LIST folder_list = mailbox.folder.list(mailbox.folder_test) - self.assertEqual( - set([i['name'] for i in folder_list]), - {mailbox.folder_test_base, mailbox.folder_test_temp1, mailbox.folder_test_temp2} - ) + check_folder_set = {mailbox.folder_test_base, mailbox.folder_test_temp1, mailbox.folder_test_temp2} + self.assertTrue(check_folder_set.issubset(set([i['name'] for i in folder_list]))) for folder in folder_list: self.assertIs(type(folder['flags']), str) self.assertIs(type(folder['delim']), str) diff --git a/tests/test_message.py b/tests/test_message.py index 2a3daa4..7571948 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -4,7 +4,7 @@ from tests.utils import MailboxTestCase from tests.data import MESSAGE_ATTRIBUTES -from imap_tools import MailMessage +from imap_tools import MailMessage, MessageFlags class MessageTest(MailboxTestCase): @@ -13,6 +13,7 @@ def test_live(self): none_type = type(None) for mailbox in self.mailbox_set.values(): mailbox.folder.set(mailbox.folder_test_base) + answered_and_flagged_cnt = 0 for message in mailbox.fetch(): self.assertIn(type(message.uid), (str, none_type)) self.assertIs(type(message.subject), str) @@ -35,12 +36,16 @@ def test_live(self): self.assertIs(type(message.flags), tuple) for i in message.flags: self.assertIs(type(i), str) + if {MessageFlags.ANSWERED, MessageFlags.FLAGGED}.issubset(message.flags): + answered_and_flagged_cnt += 1 for att in message.attachments: self.assertIs(type(att.filename), str) self.assertIs(type(att.content_type), str) self.assertIs(type(att.payload), bytes) + self.assertTrue(answered_and_flagged_cnt >= 1) + def test_attributes(self): msg_attr_set = {'subject', 'from_', 'to', 'cc', 'bcc', 'reply_to', 'date', 'date_str', 'text', 'html', 'headers', 'from_values', 'to_values', 'cc_values', 'bcc_values', 'reply_to_values'} diff --git a/tests/utils.py b/tests/utils.py index 777fd9e..e994196 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -3,7 +3,8 @@ import configparser from imap_tools import MailBox -test_mailbox_name_set = {'YANDEX', 'ZIMBRA', 'MAIL_RU'} # YANDEX, MAIL_RU, GOOGLE, ZIMBRA +# YANDEX, MAIL_RU, GOOGLE, ZIMBRA, OUTLOOK +TEST_MAILBOX_NAME_SET = {'YANDEX', 'ZIMBRA', 'MAIL_RU', 'OUTLOOK'} def get_test_mailbox_config(mailbox_name: str) -> dict: @@ -17,6 +18,7 @@ def get_test_mailbox_config(mailbox_name: str) -> dict: email=config[mailbox_name]['email'], password=config[mailbox_name]['password'], path_separator=config[mailbox_name]['path_separator'], + test_folder=config[mailbox_name]['test_folder'], ) @@ -24,27 +26,23 @@ def get_test_mailbox(mailbox_name: str): # get config config = get_test_mailbox_config(mailbox_name) - # add class attributes for pycharm code analyzer + # add test attributes to MailBox class MailBoxTestEx(MailBox): def __init__(self, *args): super().__init__(*args) - self.folder_test = 'test' - self.folder_test_base = 'test{}base' - self.folder_test_temp1 = 'test{}temp1' - self.folder_test_temp2 = 'test{}temp2' - self.folder_test_new = 'test{}new' - self.folder_test_new1 = 'test{}new1' + test_folder = config['test_folder'] + path_separator = config['path_separator'] + self.folder_test = '{}'.format(test_folder) + self.folder_test_base = '{}{}base'.format(test_folder, path_separator) + self.folder_test_temp1 = '{}{}temp1'.format(test_folder, path_separator) + self.folder_test_temp2 = '{}{}temp2'.format(test_folder, path_separator) + self.folder_test_new = '{}{}new'.format(test_folder, path_separator) + self.folder_test_new1 = '{}{}new1'.format(test_folder, path_separator) # create mailbox instance mailbox = MailBoxTestEx(config['host']) # connect mailbox.login(config['email'], config['password']) - # set test folder paths - mailbox.folder_test_base = mailbox.folder_test_base.format(config['path_separator']) - mailbox.folder_test_temp1 = mailbox.folder_test_temp1.format(config['path_separator']) - mailbox.folder_test_temp2 = mailbox.folder_test_temp2.format(config['path_separator']) - mailbox.folder_test_new = mailbox.folder_test_new.format(config['path_separator']) - mailbox.folder_test_new1 = mailbox.folder_test_new1.format(config['path_separator']) # done return mailbox @@ -52,7 +50,7 @@ def __init__(self, *args): class MailboxTestCase(unittest.TestCase): def setUp(self): self.mailbox_set = dict() - for test_mailbox_name in test_mailbox_name_set: + for test_mailbox_name in TEST_MAILBOX_NAME_SET: self.mailbox_set[test_mailbox_name] = get_test_mailbox(test_mailbox_name) def tearDown(self):