Skip to content

Commit

Permalink
♻️ Tests bad parsing of jobs custom metadata (#6559)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Oct 18, 2024
1 parent d200c57 commit 91ca56e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
)

JobID: TypeAlias = UUID
assert JobID == ProjectID

# ArgumentTypes are types used in the job inputs (see ResultsTypes)
ArgumentTypes: TypeAlias = (
Expand Down
11 changes: 11 additions & 0 deletions services/api-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
56 changes: 55 additions & 1 deletion services/api-server/tests/unit/test_models_schemas_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

0 comments on commit 91ca56e

Please sign in to comment.