Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix e2e tests #210

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/publish-python-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ jobs:
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
attestations: false
bisgaard-itis marked this conversation as resolved.
Show resolved Hide resolved
verbose: true
packages-dir: osparc_python_wheels/
34 changes: 27 additions & 7 deletions clients/python/test/e2e/test_files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from memory_profiler import memory_usage
from typing import Final, List, Callable
from pydantic import ByteSize
from _utils import skip_if_osparc_version
from packaging.version import Version

_KB: ByteSize = ByteSize(1024) # in bytes
_MB: ByteSize = ByteSize(_KB * 1024) # in bytes
Expand All @@ -33,7 +35,30 @@ def _hash_file(file: Path) -> str:
def test_upload_file(
create_tmp_file: Callable[[ByteSize], Path], api_client: osparc.ApiClient
) -> None:
"""Test that we can upload a file via the multipart upload and download it again. Also check RAM usage of upload/download fcns"""
"""Test that we can upload a file via the multipart upload and download it again."""
tmp_file = create_tmp_file(ByteSize(1 * _GB))
tmp_path: Path = tmp_file.parent
files_api: osparc.FilesApi = osparc.FilesApi(api_client=api_client)
try:
uploaded_file1: osparc.File = files_api.upload_file(tmp_file)
uploaded_file2: osparc.File = files_api.upload_file(tmp_file)
assert (
uploaded_file1.id == uploaded_file2.id
), "could not detect that file was already on server"
downloaded_file = files_api.download_file(
uploaded_file1.id, destination_folder=tmp_path, retval=True
)
assert Path(downloaded_file).parent == tmp_path
assert _hash_file(Path(downloaded_file)) == _hash_file(tmp_file)
finally:
files_api.delete_file(uploaded_file1.id)
bisgaard-itis marked this conversation as resolved.
Show resolved Hide resolved


@skip_if_osparc_version(at_least=Version("0.8.3.post0.dev12"))
def test_upload_download_file_ram_usage(
create_tmp_file: Callable[[ByteSize], Path], api_client: osparc.ApiClient
) -> None:
"""Check RAM usage of upload/download fcns"""
_allowed_ram_usage_in_mb: Final[int] = 300 # 300MB
tmp_file = create_tmp_file(ByteSize(1 * _GB))
assert (
Expand All @@ -53,10 +78,6 @@ def max_diff(data: List[int]) -> int:
assert (
max_diff(upload_ram_usage_in_mb) < _allowed_ram_usage_in_mb
), f"Used more than {_allowed_ram_usage_in_mb=} to upload file of size {tmp_file.stat().st_size=}"
uploaded_file2: osparc.File = files_api.upload_file(tmp_file)
assert (
uploaded_file1.id == uploaded_file2.id
), "could not detect that file was already on server"
download_ram_usage_in_mb, downloaded_file = memory_usage(
(
files_api.download_file,
Expand All @@ -67,8 +88,7 @@ def max_diff(data: List[int]) -> int:
)
assert (
max_diff(download_ram_usage_in_mb) < _allowed_ram_usage_in_mb
), f"Used more than {_allowed_ram_usage_in_mb=} to down file of size {Path(downloaded_file).stat().st_size=}"
assert Path(downloaded_file).parent == tmp_path
), f"Used more than {_allowed_ram_usage_in_mb=} to download file of size {Path(downloaded_file).stat().st_size=}"
assert _hash_file(Path(downloaded_file)) == _hash_file(tmp_file)
finally:
files_api.delete_file(uploaded_file1.id)
Expand Down
Loading