-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1648 from fractal-analytics-platform/1644-log-fil…
…es-for-failed-task-are-not-downloadable-from-fractal-web-after-job-execution-error Correctly zip structured folders
- Loading branch information
Showing
7 changed files
with
57 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/no_version/test_unit_test_zip_folder_to_byte_stream.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from pathlib import Path | ||
from zipfile import ZipFile | ||
|
||
from devtools import debug | ||
|
||
from fractal_server.app.routes.aux._job import _zip_folder_to_byte_stream | ||
|
||
|
||
def test_zip_folder_to_byte_stream(tmp_path: Path): | ||
debug(tmp_path) | ||
|
||
# Prepare file/folder structure | ||
(tmp_path / "file1").touch() | ||
(tmp_path / "file2").touch() | ||
(tmp_path / "folder").mkdir() | ||
(tmp_path / "folder/file3").touch() | ||
(tmp_path / "folder/file4").touch() | ||
|
||
output = _zip_folder_to_byte_stream(folder=tmp_path.as_posix()) | ||
|
||
# Write BytesIO to file | ||
archive_path = tmp_path / "zipped_folder.zip" | ||
with archive_path.open("wb") as f: | ||
f.write(output.getbuffer()) | ||
|
||
# Unzip the log archive | ||
unzipped_archived_path = tmp_path / "unzipped_folder" | ||
unzipped_archived_path.mkdir() | ||
with ZipFile(archive_path.as_posix(), mode="r") as zipfile: | ||
zipfile.extractall(path=unzipped_archived_path.as_posix()) | ||
|
||
# Verify that all expected items are present | ||
glob_list = [file.name for file in unzipped_archived_path.rglob("*")] | ||
debug(glob_list) | ||
assert "file1" in glob_list | ||
assert "file2" in glob_list | ||
assert "folder" in glob_list | ||
assert "file3" in glob_list | ||
assert "file4" in glob_list |