diff --git a/requirements-test.txt b/requirements-test.txt index 71856db016..10a360d7f4 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -3,6 +3,7 @@ checksumdir~=1.2.0 pytest~=8.3.0 pytest-xdist~=3.6.0 pytest-cov~=4.0.0 +pytest-mock~=3.14.0 # In this version DataFrame conversion to Excel is done using 'xlsxwriter' library. # But Excel files reading is done using 'openpyxl' library, during testing only. diff --git a/tests/integration/filesystem_blueprint/test_filesystem_endpoints.py b/tests/integration/filesystem_blueprint/test_filesystem_endpoints.py index d1e344e73d..54c16e41fc 100644 --- a/tests/integration/filesystem_blueprint/test_filesystem_endpoints.py +++ b/tests/integration/filesystem_blueprint/test_filesystem_endpoints.py @@ -13,10 +13,10 @@ import datetime import operator import re -import shutil import typing as t from pathlib import Path +from pytest_mock import MockerFixture from starlette.testclient import TestClient from tests.integration.conftest import RESOURCES_DIR @@ -93,6 +93,7 @@ def test_lifecycle( client: TestClient, user_access_token: str, admin_access_token: str, + mocker: MockerFixture ) -> None: """ Test the lifecycle of the filesystem endpoints. @@ -102,7 +103,7 @@ def test_lifecycle( caplog: pytest caplog fixture. client: test client (tests.integration.conftest.client_fixture). user_access_token: access token of a classic user (tests.integration.conftest.user_access_token_fixture). - admin_access_token: access token of an admin user (tests.integration.conftest.admin_access_token_fixture). + admin_access_token: access token of an admin user (tests.integration.conftestin_access_token_fixture). """ # NOTE: all the following paths are based on the configuration defined in the app_fixture. archive_dir = tmp_path / "archive_dir" @@ -165,26 +166,25 @@ def test_lifecycle( err_count += 1 # Known filesystem + mocker.patch("shutil.disk_usage", return_value=(100, 200, 300)) res = client.get("/v1/filesystem/ws", headers=user_headers) assert res.status_code == 200, res.json() actual = sorted(res.json(), key=operator.itemgetter("name")) - # Both mount point are in the same filesystem, which is the `tmp_path` filesystem - total_bytes, used_bytes, free_bytes = shutil.disk_usage(tmp_path) expected = [ { "name": "default", "path": str(default_workspace), - "total_bytes": total_bytes, - "used_bytes": used_bytes, - "free_bytes": free_bytes, + "total_bytes": 100, + "used_bytes": 200, + "free_bytes": 300, "message": AnyDiskUsagePercent(), }, { "name": "ext", "path": str(ext_workspace_path), - "total_bytes": total_bytes, - "used_bytes": used_bytes, - "free_bytes": free_bytes, + "total_bytes": 100, + "used_bytes": 200, + "free_bytes": 300, "message": AnyDiskUsagePercent(), }, ] @@ -206,9 +206,9 @@ def test_lifecycle( expected = { "name": "default", "path": str(default_workspace), - "total_bytes": total_bytes, - "used_bytes": used_bytes, - "free_bytes": free_bytes, + "total_bytes": 100, + "used_bytes": 200, + "free_bytes": 300, "message": AnyDiskUsagePercent(), } assert actual == expected diff --git a/tests/integration/filesystem_blueprint/test_model.py b/tests/integration/filesystem_blueprint/test_model.py index 67f5518f1d..a4f909b30b 100644 --- a/tests/integration/filesystem_blueprint/test_model.py +++ b/tests/integration/filesystem_blueprint/test_model.py @@ -16,6 +16,8 @@ import shutil from pathlib import Path +from pytest_mock import MockerFixture + from antarest.core.filesystem_blueprint import FileInfoDTO, FilesystemDTO, MountPointDTO @@ -63,15 +65,16 @@ def test_from_path__missing_file(self) -> None: assert dto.free_bytes == 0 assert dto.message.startswith("N/A:"), dto.message - def test_from_path__file(self, tmp_path: Path) -> None: + def test_from_path__file(self, tmp_path: Path, mocker: MockerFixture) -> None: + mocker.patch("shutil.disk_usage", return_value=(100, 200, 300)) + name = "foo" dto = MountPointDTO.from_path(name, tmp_path) - total_bytes, used_bytes, free_bytes = shutil.disk_usage(tmp_path) assert dto.name == name assert dto.path == tmp_path - assert dto.total_bytes == total_bytes - assert dto.used_bytes == used_bytes - assert dto.free_bytes == free_bytes + assert dto.total_bytes == 100 + assert dto.used_bytes == 200 + assert dto.free_bytes == 300 assert re.fullmatch(r"\d+(?:\.\d+)?% used", dto.message), dto.message