Move IMAPMockServer to its own module
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -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
|
||||
|
||||
36
mayan/apps/sources/tests/mocks.py
Normal file
36
mayan/apps/sources/tests/mocks.py
Normal file
@@ -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'])
|
||||
@@ -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=''
|
||||
|
||||
Reference in New Issue
Block a user