Skip to content

Commit fe4f50c

Browse files
🐛 Fix e2e tests (#210)
1 parent 0fb24bd commit fe4f50c

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

.github/workflows/publish-python-client.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ jobs:
3232
- name: Publish to PyPI
3333
uses: pypa/gh-action-pypi-publish@release/v1
3434
with:
35+
attestations: false
3536
verbose: true
3637
packages-dir: osparc_python_wheels/

clients/python/test/e2e/test_files_api.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from memory_profiler import memory_usage
1313
from typing import Final, List, Callable
1414
from pydantic import ByteSize
15+
from _utils import skip_if_osparc_version
16+
from packaging.version import Version
1517

1618
_KB: ByteSize = ByteSize(1024) # in bytes
1719
_MB: ByteSize = ByteSize(_KB * 1024) # in bytes
@@ -33,7 +35,30 @@ def _hash_file(file: Path) -> str:
3335
def test_upload_file(
3436
create_tmp_file: Callable[[ByteSize], Path], api_client: osparc.ApiClient
3537
) -> None:
36-
"""Test that we can upload a file via the multipart upload and download it again. Also check RAM usage of upload/download fcns"""
38+
"""Test that we can upload a file via the multipart upload and download it again."""
39+
tmp_file = create_tmp_file(ByteSize(1 * _GB))
40+
tmp_path: Path = tmp_file.parent
41+
files_api: osparc.FilesApi = osparc.FilesApi(api_client=api_client)
42+
try:
43+
uploaded_file1: osparc.File = files_api.upload_file(tmp_file)
44+
uploaded_file2: osparc.File = files_api.upload_file(tmp_file)
45+
assert (
46+
uploaded_file1.id == uploaded_file2.id
47+
), "could not detect that file was already on server"
48+
downloaded_file = files_api.download_file(
49+
uploaded_file1.id, destination_folder=tmp_path, retval=True
50+
)
51+
assert Path(downloaded_file).parent == tmp_path
52+
assert _hash_file(Path(downloaded_file)) == _hash_file(tmp_file)
53+
finally:
54+
files_api.delete_file(uploaded_file1.id)
55+
56+
57+
@skip_if_osparc_version(at_least=Version("0.8.3.post0.dev12"))
58+
def test_upload_download_file_ram_usage(
59+
create_tmp_file: Callable[[ByteSize], Path], api_client: osparc.ApiClient
60+
) -> None:
61+
"""Check RAM usage of upload/download fcns"""
3762
_allowed_ram_usage_in_mb: Final[int] = 300 # 300MB
3863
tmp_file = create_tmp_file(ByteSize(1 * _GB))
3964
assert (
@@ -53,10 +78,6 @@ def max_diff(data: List[int]) -> int:
5378
assert (
5479
max_diff(upload_ram_usage_in_mb) < _allowed_ram_usage_in_mb
5580
), f"Used more than {_allowed_ram_usage_in_mb=} to upload file of size {tmp_file.stat().st_size=}"
56-
uploaded_file2: osparc.File = files_api.upload_file(tmp_file)
57-
assert (
58-
uploaded_file1.id == uploaded_file2.id
59-
), "could not detect that file was already on server"
6081
download_ram_usage_in_mb, downloaded_file = memory_usage(
6182
(
6283
files_api.download_file,
@@ -67,8 +88,7 @@ def max_diff(data: List[int]) -> int:
6788
)
6889
assert (
6990
max_diff(download_ram_usage_in_mb) < _allowed_ram_usage_in_mb
70-
), f"Used more than {_allowed_ram_usage_in_mb=} to down file of size {Path(downloaded_file).stat().st_size=}"
71-
assert Path(downloaded_file).parent == tmp_path
91+
), f"Used more than {_allowed_ram_usage_in_mb=} to download file of size {Path(downloaded_file).stat().st_size=}"
7292
assert _hash_file(Path(downloaded_file)) == _hash_file(tmp_file)
7393
finally:
7494
files_api.delete_file(uploaded_file1.id)

0 commit comments

Comments
 (0)