diff --git a/amt/utils/path.py b/amt/utils/path.py deleted file mode 100644 index 8c7172e1..00000000 --- a/amt/utils/path.py +++ /dev/null @@ -1,12 +0,0 @@ -from pathlib import Path - - -def is_safe_path(basedir: Path, path: Path, follow_symlinks: bool = True) -> bool: - # Resolve the absolute path of the base directory - base = basedir.resolve() - - # Resolve the absolute path of the provided path - target = path.resolve() if follow_symlinks else path - - # Check if the target path starts with the base directory path - return target.is_relative_to(base) or base == target diff --git a/amt/utils/storage.py b/amt/utils/storage.py deleted file mode 100644 index 3ce57190..00000000 --- a/amt/utils/storage.py +++ /dev/null @@ -1,38 +0,0 @@ -import logging -from pathlib import Path -from typing import Any - -from amt.services.storage import StorageFactory - -logger = logging.getLogger(__name__) - - -def get_include_content(base_dir: Path, system_card: str, include_name: str, search_key: str) -> dict[str, Any] | None: - """ - Searches for `search_key` in the `include_name` fields in the system card. `include_name` can be `assessments` or - `models`. - Example: - base_dir = / - system_card = "system_card.yaml" - include_name = "assessments" - search_key = "IAMA" - - Suppose the system_card.yaml contains the following: - ``` - assessments: - - name: "IAMA" - ... - - name: "AIIA" - ``` - Then the function would return the contents of the assessment with name equal to "IAMA". - - """ - storage_service = StorageFactory.init(storage_type="file", location=base_dir, filename=system_card) - system_card_data: Any = storage_service.read() - - for content in system_card_data[include_name]: - if search_key.lower() in content["name"].lower(): - return content - - logger.warning("could not fetch contents") - return None diff --git a/pyproject.toml b/pyproject.toml index e5e80b8c..9ba93be2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -115,10 +115,10 @@ relative_files = true # needed for sonarcloud code coverage omit = [ "tests/*" ] - +concurrency = ["greenlet", "thread"] [tool.coverage.report] -fail_under = 75 +fail_under = 95 [tool.coverage.html] directory = "htmlcov" diff --git a/tests/api/routes/test_auth.py b/tests/api/routes/test_auth.py new file mode 100644 index 00000000..e127fbe2 --- /dev/null +++ b/tests/api/routes/test_auth.py @@ -0,0 +1,11 @@ +import pytest +from httpx import AsyncClient +from pytest_mock import MockerFixture + + +@pytest.mark.asyncio +async def test_auth_profile(client: AsyncClient, mocker: MockerFixture) -> None: + mocker.patch("amt.api.routes.auth.get_user", return_value="test_user_for_auth_profile") + response = await client.get("/auth/profile") + + assert b"https://gravatar.com/" in response.content diff --git a/tests/api/routes/test_project.py b/tests/api/routes/test_project.py index 9a6e159b..c992b085 100644 --- a/tests/api/routes/test_project.py +++ b/tests/api/routes/test_project.py @@ -1,12 +1,23 @@ from typing import Any import pytest -from amt.api.routes.project import set_path +from amt.api.routes.project import ( + MeasureUpdate, + find_measure_task, + find_requirement_task, + find_requirement_tasks_by_measure_urn, + get_project_context, + get_project_or_error, + set_path, +) +from amt.core.exceptions import AMTNotFound, AMTRepositoryError from amt.models import Project +from amt.schema.task import MovedTask from httpx import AsyncClient from pytest_httpx import HTTPXMock from pytest_mock import MockFixture +from tests.api.routes.test_projects import MockRequest from tests.constants import ( TASK_REGISTRY_AIIA_CONTENT_PAYLOAD, TASK_REGISTRY_CONTENT_PAYLOAD, @@ -43,6 +54,96 @@ async def test_get_project_tasks(client: AsyncClient, db: DatabaseTestUtils) -> assert b"Default Task" in response.content +@pytest.mark.asyncio +async def test_get_project_inference(client: AsyncClient, db: DatabaseTestUtils) -> None: + # given + await db.given([default_project("testproject1"), default_task(project_id=1, status_id=1)]) + + # when + response = await client.get("/algorithm-system/1/details/model/inference") + + # then + assert response.status_code == 200 + assert response.headers["content-type"] == "text/html; charset=utf-8" + assert b'