From 91ca56ee67c0e9fd930359342d359528d6e34f0e Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:53:41 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Tests=20bad=20parsing=20of?= =?UTF-8?q?=20jobs=20custom=20metadata=20(#6559)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/schemas/jobs.py | 1 + services/api-server/tests/conftest.py | 11 ++++ .../tests/unit/test_models_schemas_jobs.py | 56 ++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/services/api-server/src/simcore_service_api_server/models/schemas/jobs.py b/services/api-server/src/simcore_service_api_server/models/schemas/jobs.py index a190d4e182b..e6f5edf51b9 100644 --- a/services/api-server/src/simcore_service_api_server/models/schemas/jobs.py +++ b/services/api-server/src/simcore_service_api_server/models/schemas/jobs.py @@ -34,6 +34,7 @@ ) JobID: TypeAlias = UUID +assert JobID == ProjectID # ArgumentTypes are types used in the job inputs (see ResultsTypes) ArgumentTypes: TypeAlias = ( diff --git a/services/api-server/tests/conftest.py b/services/api-server/tests/conftest.py index 25180a27491..e2b885bffa9 100644 --- a/services/api-server/tests/conftest.py +++ b/services/api-server/tests/conftest.py @@ -8,7 +8,10 @@ import pytest import simcore_service_api_server from dotenv import dotenv_values +from models_library.projects import ProjectID +from pydantic import parse_obj_as from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict +from simcore_service_api_server.models.schemas.jobs import JobID CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent @@ -96,3 +99,11 @@ def tests_utils_dir(project_tests_dir: Path) -> Path: utils_dir = (project_tests_dir / "utils").resolve() assert utils_dir.exists() return utils_dir + + +## BASIC IDENTIFIERS --- + + +@pytest.fixture +def job_id(project_id: ProjectID) -> JobID: + return parse_obj_as(JobID, project_id) diff --git a/services/api-server/tests/unit/test_models_schemas_jobs.py b/services/api-server/tests/unit/test_models_schemas_jobs.py index afb1d6e1966..c1e3a905fbc 100644 --- a/services/api-server/tests/unit/test_models_schemas_jobs.py +++ b/services/api-server/tests/unit/test_models_schemas_jobs.py @@ -3,14 +3,23 @@ # pylint: disable=unused-variable import random +import textwrap import urllib.parse from copy import deepcopy from uuid import uuid4 import pytest +from faker import Faker from fastapi import FastAPI +from models_library.api_schemas_webserver.projects_metadata import ProjectMetadataGet +from models_library.generics import Envelope from simcore_service_api_server._meta import API_VTAG -from simcore_service_api_server.models.schemas.jobs import Job, JobInputs +from simcore_service_api_server.models.schemas.jobs import ( + Job, + JobID, + JobInputs, + JobMetadata, +) from simcore_service_api_server.models.schemas.solvers import Solver @@ -70,3 +79,48 @@ def test_job_resouce_names_has_associated_url(app: FastAPI): ) assert url_path == f"/{API_VTAG}/{urllib.parse.unquote_plus(job_name)}" + + +@pytest.mark.acceptance_test( + "Fixing https://github.com/ITISFoundation/osparc-simcore/issues/6556" +) +def test_parsing_job_custom_metadata(job_id: JobID, faker: Faker): + job_name = faker.name() + + got = Envelope[ProjectMetadataGet].parse_raw( + textwrap.dedent( + f""" + {{ + "data": {{ + "projectUuid": "{job_id}", + "custom": {{ + "number": 3.14, + "string": "foo", + "boolean": true, + "integer": 42, + "job_id": "{job_id}", + "job_name": "{job_name}" + }} + }} + }} + """ + ) + ) + + assert got.data + assert got.data.custom == { + "number": 3.14, + "string": "foo", + "boolean": True, + "integer": 42, + "job_id": f"{job_id}", + "job_name": job_name, + } + + j = JobMetadata( + job_id=job_id, + metadata=got.data.custom or {}, + url=faker.url(), + ) + + assert j.metadata == got.data.custom