aboutsummaryrefslogblamecommitdiffstats
path: root/test/test_email_server.py
blob: 8ff87886ba2f9450be903e02e7d37b8e50bece8c (plain) (tree)
1
2
3
4
5
6
7
8
9
              




                         
                               

                                         
                                                                          
















                                                                                  
import logging
import unittest
from unittest import mock

import archive_folder

log = logging.getLogger('test')

class TestEmailServer(unittest.TestCase):
    @mock.patch.object(archive_folder.imaplib, 'IMAP4_SSL', autospec=True)
    @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))