Skip to content

Commit

Permalink
fixes models
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Oct 29, 2024
1 parent 63721fa commit b051792
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ServiceMetaDataEditable(ServiceBaseDisplay):
for n in range(1, 11)
},
},
"classifiers": [],
}
}
)
28 changes: 14 additions & 14 deletions services/catalog/src/simcore_service_catalog/models/services_db.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from datetime import datetime
from typing import Any, ClassVar
from typing import Any

from models_library.products import ProductName
from models_library.services_access import ServiceGroupAccessRights
from models_library.services_base import ServiceKeyVersion
from models_library.services_metadata_editable import ServiceMetaDataEditable
from models_library.services_types import ServiceKey, ServiceVersion
from pydantic import BaseModel, Field
from pydantic import BaseModel, ConfigDict, Field
from pydantic.types import PositiveInt
from simcore_postgres_database.models.services_compatibility import CompatiblePolicyDict

Expand All @@ -15,10 +15,9 @@ class ServiceMetaDataAtDB(ServiceKeyVersion, ServiceMetaDataEditable):
# for a partial update all members must be Optional
classifiers: list[str] | None = Field(default_factory=list)
owner: PositiveInt | None

class Config:
orm_mode = True
schema_extra: ClassVar[dict[str, Any]] = {
model_config = ConfigDict(
from_attributes=True,
json_schema_extra={
"example": {
"key": "simcore/services/dynamic/sim4life",
"version": "1.0.9",
Expand Down Expand Up @@ -49,7 +48,8 @@ class Config:
},
},
}
}
},
)


class ReleaseFromDB(BaseModel):
Expand Down Expand Up @@ -83,19 +83,18 @@ class ServiceWithHistoryFromDB(BaseModel):


assert ( # nosec
set(ReleaseFromDB.__fields__)
set(ReleaseFromDB.model_fields)
.difference({"compatibility_policy"})
.issubset(set(ServiceWithHistoryFromDB.__fields__))
.issubset(set(ServiceWithHistoryFromDB.model_fields))
)


class ServiceAccessRightsAtDB(ServiceKeyVersion, ServiceGroupAccessRights):
gid: PositiveInt
product_name: ProductName

class Config:
orm_mode = True
schema_extra: ClassVar[dict[str, Any]] = {
model_config = ConfigDict(
from_attributes=True,
json_schema_extra={
"example": {
"key": "simcore/services/dynamic/sim4life",
"version": "1.0.9",
Expand All @@ -106,4 +105,5 @@ class Config:
"created": "2021-01-18 12:46:57.7315",
"modified": "2021-01-19 12:45:00",
}
}
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
)
from models_library.services import ServiceKey, ServiceVersion
from models_library.users import GroupID
from pydantic import ConfigDict


class ServiceSpecificationsAtDB(ServiceSpecifications):
service_key: ServiceKey
service_version: ServiceVersion
gid: GroupID

class Config(ServiceSpecifications.Config):
orm_mode: bool = True
model_config = ConfigDict(from_attributes=True)
28 changes: 28 additions & 0 deletions services/catalog/tests/unit/test__model_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# pylint: disable=protected-access
# pylint: disable=redefined-outer-name
# pylint: disable=too-many-arguments
# pylint: disable=unused-argument
# pylint: disable=unused-variable

import json
from typing import Any

import pytest
import simcore_service_catalog.models
from pydantic import BaseModel, ValidationError
from pytest_simcore.pydantic_models import walk_model_examples_in_package


@pytest.mark.parametrize(
"model_cls, example_name, example_data",
walk_model_examples_in_package(simcore_service_catalog.models),
)
def test_catalog_service_model_examples(
model_cls: type[BaseModel], example_name: int, example_data: Any
):
try:
assert model_cls.model_validate(example_data) is not None
except ValidationError as err:
pytest.fail(
f"\n{example_name}: {json.dumps(example_data, indent=1)}\nError: {err}"
)

0 comments on commit b051792

Please sign in to comment.