Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestaP committed Jul 22, 2024
1 parent baa9472 commit e507264
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions tests/units/common/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e507264

Please sign in to comment.