From e5072645b7b399c3990f70b856485a1c26119e63 Mon Sep 17 00:00:00 2001 From: ErnestaP Date: Mon, 22 Jul 2024 21:42:53 +0200 Subject: [PATCH] test --- tests/units/common/test_common.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/units/common/test_common.py b/tests/units/common/test_common.py index a7dce6b3..6925630e 100644 --- a/tests/units/common/test_common.py +++ b/tests/units/common/test_common.py @@ -23,6 +23,14 @@ {"xml": f, "pdf": f} for f in SFTP_LIST_FILES_RETURN_VALUE ] +@pytest.fixture +def tar_fixture(): + with patch("tarfile.open", autospec=True) as tar_patch: + mock_tararchive = MagicMock() + mock_tararchive.getnames.return_value = SFTP_TAR_FILES + mock_tararchive.extractfile.return_value.read.return_value = BytesIO(b"file content").read() + tar_patch.return_value.__enter__.return_value = mock_tararchive + yield tar_patch @pytest.fixture def zip_fixture(): @@ -33,15 +41,6 @@ def zip_fixture(): zip_patch.return_value.__enter__ = mock_ziparchive yield zip_patch -@pytest.fixture -def tar_fixture(): - with patch("tarfile.open", autospec=True) as tar_patch: - mock_tararchive = MagicMock() - mock_tararchive.getnames.return_value = SFTP_TAR_FILES - mock_tararchive.extractfile.return_value.read.return_value = BytesIO(b"file content").read() - tar_patch.return_value.__enter__.return_value = mock_tararchive - yield tar_patch - @pytest.fixture def ftp_get_file_fixture(): with patch.object(SFTPService, attribute="get_file") as patched: @@ -139,8 +138,8 @@ def test_migrate_from_ftp_only_one_file_but_force_flag( repo_is_meta, sftp_list_files, ftp_get_file_fixture, - zip_fixture, tar_fixture, + zip_fixture, ): with SFTPService() as sftp: repo = IRepository() @@ -176,8 +175,8 @@ def test_migrate_from_ftp_specified_file_force_from_ftp( repo_is_meta, sftp_list_files, ftp_get_file_fixture, - zip_fixture, tar_fixture, + zip_fixture, ): repo_get_all.return_value = SFTP_ZIP_FILES[0:-1] with SFTPService() as sftp: @@ -217,8 +216,8 @@ def test_migrate_from_ftp_specified_file( sftp_list_files, ftp_init, ftp_get_file_fixture, - zip_fixture, tar_fixture, + zip_fixture, ): repo_get_all.return_value = SFTP_ZIP_FILES[0:-1] repo = IRepository() @@ -253,8 +252,8 @@ def test_migrate_from_ftp_specified_file( sftp_list_files, ftp_init, ftp_get_file_fixture, - zip_fixture, tar_fixture, + zip_fixture, ): repo_get_all.return_value = SFTP_ZIP_FILES[0:-1] repo = IRepository() @@ -286,8 +285,8 @@ def test_migrate_from_ftp_specified_file_force_from_ftp( repo_is_meta, sftp_list_files, ftp_get_file_fixture, - zip_fixture, tar_fixture, + zip_fixture, ): repo_get_all.return_value = SFTP_ZIP_FILES[0:-1] with SFTPService() as sftp: