From 274937feeeb570c17f8d8e6d4a852490d180063d Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sun, 3 Nov 2019 18:36:33 -0400 Subject: [PATCH] Move remaining mocked objects to mocks.py module Signed-off-by: Roberto Rosario --- mayan/apps/sources/tests/mocks.py | 29 ++++++++++++++++++++++++ mayan/apps/sources/tests/test_classes.py | 5 ++-- mayan/apps/sources/tests/test_models.py | 28 ++--------------------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/mayan/apps/sources/tests/mocks.py b/mayan/apps/sources/tests/mocks.py index 3e3c4b43eb..f66e9a0cfd 100644 --- a/mayan/apps/sources/tests/mocks.py +++ b/mayan/apps/sources/tests/mocks.py @@ -34,3 +34,32 @@ class MockIMAPServer(object): def logout(self): return ('BYE', ['LOGOUT Requested']) + + +class MockMailbox(object): + def dele(self, which): + return + + def getwelcome(self): + return + + def list(self, which=None): + return (None, ['1 test']) + + def user(self, user): + return + + def pass_(self, pswd): + return + + def quit(self): + return + + def retr(self, which=None): + return ( + 1, [TEST_EMAIL_BASE64_FILENAME] + ) + + +class MockStagingFolder(object): + """Mock of a StagingFolder model""" diff --git a/mayan/apps/sources/tests/test_classes.py b/mayan/apps/sources/tests/test_classes.py index 319c3eeb37..b20e63aa62 100644 --- a/mayan/apps/sources/tests/test_classes.py +++ b/mayan/apps/sources/tests/test_classes.py @@ -9,6 +9,8 @@ from mayan.apps.storage.utils import mkdtemp from ..classes import StagingFile +from .mocks import MockStagingFolder + class StagingFileTestCase(BaseTestCase): def test_unicode_staging_file(self): @@ -17,9 +19,6 @@ class StagingFileTestCase(BaseTestCase): filename = os.path.basename(TEST_NON_ASCII_DOCUMENT_PATH) - class MockStagingFolder(object): - self.folder_path = temporary_directory - staging_file_1 = StagingFile( staging_folder=MockStagingFolder(), filename=filename diff --git a/mayan/apps/sources/tests/test_models.py b/mayan/apps/sources/tests/test_models.py index 0fbc61ce05..8121566f10 100644 --- a/mayan/apps/sources/tests/test_models.py +++ b/mayan/apps/sources/tests/test_models.py @@ -29,7 +29,7 @@ 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 .mocks import MockIMAPServer, MockMailbox from .literals import ( @@ -288,33 +288,9 @@ class IMAPSourceTestCase(GenericDocumentTestCase): class POP3SourceTestCase(GenericDocumentTestCase): auto_upload_document = False - class MockMailbox(object): - def dele(self, which): - return - - def getwelcome(self): - return - - def list(self, which=None): - return (None, ['1 test']) - - def user(self, user): - return - - def pass_(self, pswd): - return - - def quit(self): - return - - def retr(self, which=None): - return ( - 1, [TEST_EMAIL_BASE64_FILENAME] - ) - @mock.patch('poplib.POP3_SSL', autospec=True) def test_download_document(self, mock_poplib): - mock_poplib.return_value = POP3SourceTestCase.MockMailbox() + mock_poplib.return_value = MockMailbox() self.source = POP3Email.objects.create( document_type=self.test_document_type, label='', host='', password='', username=''