diff --git a/HISTORY.rst b/HISTORY.rst index a2152d5e41..79892dba3a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,3 +1,7 @@ +3.2.9 (2019-XX-XX) +================== +- Move IMAPMockServer to its own module. + 3.2.8 (2019-10-01) ================== - Fix error when accessing some API entry points without diff --git a/mayan/apps/sources/tests/mocks.py b/mayan/apps/sources/tests/mocks.py new file mode 100644 index 0000000000..3e3c4b43eb --- /dev/null +++ b/mayan/apps/sources/tests/mocks.py @@ -0,0 +1,36 @@ +from __future__ import unicode_literals + +from .literals import TEST_EMAIL_BASE64_FILENAME + + +class MockIMAPServer(object): + def login(self, user, password): + return ('OK', ['{} authenticated (Success)'.format(user)]) + + def select(self, mailbox='INBOX', readonly=False): + return ('OK', ['1']) + + def search(self, charset, *criteria): + return ('OK', ['1']) + + def fetch(self, message_set, message_parts): + return ( + 'OK', [ + ( + '1 (RFC822 {4800}', + TEST_EMAIL_BASE64_FILENAME + ), ' FLAGS (\\Seen))' + ] + ) + + def store(self, message_set, command, flags): + return ('OK', ['1 (FLAGS (\\Seen \\Deleted))']) + + def expunge(self): + return ('OK', ['1']) + + def close(self): + return ('OK', ['Returned to authenticated state. (Success)']) + + def logout(self): + return ('BYE', ['LOGOUT Requested']) diff --git a/mayan/apps/sources/tests/test_models.py b/mayan/apps/sources/tests/test_models.py index 54ccda5fc2..0fbc61ce05 100644 --- a/mayan/apps/sources/tests/test_models.py +++ b/mayan/apps/sources/tests/test_models.py @@ -29,6 +29,9 @@ from ..literals import SOURCE_UNCOMPRESS_CHOICE_Y from ..models.email_sources import EmailBaseModel, IMAPEmail, POP3Email from ..models.watch_folder_sources import WatchFolderSource +from .mocks import MockIMAPServer + + from .literals import ( TEST_EMAIL_ATTACHMENT_AND_INLINE, TEST_EMAIL_BASE64_FILENAME, TEST_EMAIL_BASE64_FILENAME_FROM, TEST_EMAIL_BASE64_FILENAME_SUBJECT, @@ -268,41 +271,9 @@ class EmailBaseTestCase(GenericDocumentTestCase): class IMAPSourceTestCase(GenericDocumentTestCase): auto_upload_document = False - class MockIMAPServer(object): - def login(self, user, password): - return ('OK', ['{} authenticated (Success)'.format(user)]) - - def select(self, mailbox='INBOX', readonly=False): - return ('OK', ['1']) - - def search(self, charset, *criteria): - return ('OK', ['1']) - - def fetch(self, message_set, message_parts): - return ( - 'OK', [ - ( - '1 (RFC822 {4800}', - TEST_EMAIL_BASE64_FILENAME - ), ' FLAGS (\\Seen))' - ] - ) - - def store(self, message_set, command, flags): - return ('OK', ['1 (FLAGS (\\Seen \\Deleted))']) - - def expunge(self): - return ('OK', ['1']) - - def close(self): - return ('OK', ['Returned to authenticated state. (Success)']) - - def logout(self): - return ('BYE', ['LOGOUT Requested']) - @mock.patch('imaplib.IMAP4_SSL', autospec=True) def test_download_document(self, mock_imaplib): - mock_imaplib.return_value = IMAPSourceTestCase.MockIMAPServer() + mock_imaplib.return_value = MockIMAPServer() self.source = IMAPEmail.objects.create( document_type=self.test_document_type, label='', host='', password='', username=''