diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2018-04-21 22:55:05 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2018-04-21 23:03:51 +0200 |
commit | 75be2c284dc0647765046b55655ecd0dbb64f131 (patch) | |
tree | b1cff04f8f0f9a28225db70f5791b8d413dc0974 /test | |
parent | 26daa1452153ba503f8b5b941f1574275346ecfd (diff) | |
download | imapArch-75be2c284dc0647765046b55655ecd0dbb64f131.tar.gz |
Functioning tests of EmailServer creation with mock.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_email_server.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/test/test_email_server.py b/test/test_email_server.py index 3be9824..8ff8788 100644 --- a/test/test_email_server.py +++ b/test/test_email_server.py @@ -1,17 +1,27 @@ +import logging import unittest from unittest import mock import archive_folder +log = logging.getLogger('test') class TestEmailServer(unittest.TestCase): - - # Ok, data = box.login(username, password) - # Ok, data = box.capability() - @mock.patch.object(archive_folder.imaplib, 'IMAP4_SSL', autospec=True) - def test_server_initialization(self, mock_imapobj): - mock_imapobj.login.return_value = ('OK', 'FAKED success') - host = 'fakehost' - box = archive_folder.EmailServer(host, 'FakeArchive') - mock_imapobj.assert_called_with(host) + @mock.patch.object(archive_folder.configparser, 'ConfigParser', autospec=True) + def test_server_initialization(self, mock_configparser, mock_imapobj): + mock_imapobj().login.return_value = ('OK', 'FAKED success') + mock_imapobj().capability.return_value = ( + 'OK', [b'IMAP4rev1 LITERAL+ UIDPLUS'] + ) + mock_configparser().items.return_value = [ + ("host", 'fakehost'), + ('ssl', True), + ('username', 'fakeuser'), + ('password', 'veryverysecret') + ] + box = archive_folder.EmailServer('fakeuser@fakehost', 'FakeArchive') + mock_imapobj.assert_called_with(host='fakehost') + mock_imapobj().login.assert_called_once_with('fakeuser', 'veryverysecret') + mock_imapobj().capability.assert_called_once_with() + self.assertEqual(mock_imapobj().features_present, (False, True)) |