Skip to content

Commit

Permalink
unified models
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Neagu committed Jan 16, 2025
1 parent 5fe7472 commit 9eaf14c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,30 +346,3 @@ class ServiceUpdateV2(BaseModel):
assert set(ServiceUpdateV2.model_fields.keys()) - set( # nosec
ServiceGetV2.model_fields.keys()
) == {"deprecated"}


class _NodeRequirements(BaseModel):
CPU: NonNegativeInt
RAM: NonNegativeInt
model_config = ConfigDict(extra="forbid")


class ServiceExtras(BaseModel):
node_requirements: _NodeRequirements
build_date: str
vcs_ref: str
vcs_url: str

model_config = ConfigDict(
extra="forbid",
json_schema_extra={
"examples": [
{
"node_requirements": {"CPU": 4, "RAM": 2147483648},
"build_date": "2023-04-17T08:04:15Z",
"vcs_ref": "4d79449a2e79f8a3b3b2e1dd0290af9f3d1a8792",
"vcs_url": "https://github.com/ITISFoundation/jupyter-math.git",
}
]
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ServiceExtras(BaseModel):
json_schema_extra={
"examples": [
{"node_requirements": node_example}
for node_example in NodeRequirements.model_config["json_schema_extra"][
for node_example in NodeRequirements.model_json_schema()[
"examples"
] # type: ignore[index,union-attr]
]
Expand All @@ -80,7 +80,7 @@ class ServiceExtras(BaseModel):
"vcs_url": "git@github.com:ITISFoundation/osparc-simcore.git",
},
}
for node_example in NodeRequirements.model_config["json_schema_extra"][
for node_example in NodeRequirements.model_json_schema()[
"examples"
] # type: ignore[index,dict-item, union-attr]
]
Expand All @@ -94,7 +94,7 @@ class ServiceExtras(BaseModel):
},
"container_spec": {"Command": ["run", "subcommand"]},
}
for node_example in NodeRequirements.model_config["json_schema_extra"][
for node_example in NodeRequirements.model_json_schema()[
"examples"
] # type: ignore[index,union-attr]
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Annotated

from fastapi import APIRouter, Depends
from models_library.api_schemas_catalog.services import ServiceExtras
from models_library.api_schemas_directorv2.services import ServiceExtras
from models_library.services import ServiceKey, ServiceVersion

from ...services.director import DirectorApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import httpx
from common_library.json_serialization import json_dumps
from fastapi import FastAPI, HTTPException
from models_library.api_schemas_catalog.services import ServiceExtras
from models_library.api_schemas_directorv2.services import ServiceExtras
from models_library.services_metadata_published import ServiceMetaDataPublished
from models_library.services_types import ServiceKey, ServiceVersion
from pydantic import NonNegativeInt, TypeAdapter
Expand Down
4 changes: 2 additions & 2 deletions services/catalog/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from faker import Faker
from fastapi import FastAPI, status
from fastapi.testclient import TestClient
from models_library.api_schemas_catalog.services import ServiceExtras
from models_library.api_schemas_directorv2.services import ServiceExtras
from packaging.version import Version
from pydantic import EmailStr, TypeAdapter
from pytest_mock import MockerFixture, MockType
Expand Down Expand Up @@ -417,7 +417,7 @@ def _(service_key: str, service_version: str) -> dict:
"org.label-schema.vcs-ref": "4d79449a2e79f8a3b3b2e1dd0290af9f3d1a8792",
"org.label-schema.vcs-url": "https://github.com/ITISFoundation/jupyter-math.git",
"simcore.service.restart-policy": "no-restart",
"simcore.service.settings": '[{"name": "Resources", "type": "Resources", "value": {"Limits": {"NanoCPUs": 4000000000, "MemoryBytes": 2147483648}, "Reservations": {"NanoCPUs": 4000000000, "MemoryBytes": 2147483648}}}]',
"simcore.service.settings": '[{"name": "Resources", "type": "Resources", "value": {"Limits": {"NanoCPUs": 1000000000, "MemoryBytes": 4194304}, "Reservations": {"NanoCPUs": 4000000000, "MemoryBytes": 2147483648}}}]',
}

return _
Expand Down
8 changes: 6 additions & 2 deletions services/catalog/tests/unit/test_utils_service_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from models_library.api_schemas_catalog.services import ServiceExtras
from models_library.api_schemas_directorv2.services import ServiceExtras
from pydantic import TypeAdapter
from respx import MockRouter


Expand All @@ -28,4 +29,7 @@ async def test_get_service_extras(
service_version = "3.0.0"
result = await aclient.get(f"/v0/services/{service_key}/{service_version}/extras")
assert result.status_code == status.HTTP_200_OK, result.text
assert result.json() == mock_service_extras.model_dump(mode="json")

assert (
TypeAdapter(ServiceExtras).validate_python(result.json()) == mock_service_extras
)

0 comments on commit 9eaf14c

Please sign in to comment.