From c10d7d0eaa1029e2e5ce20510554bb726e7daeb3 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:51:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=E2=99=BB=EF=B8=8F=20Fix/test?= =?UTF-8?q?=20models=20(#6758)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/models-library/src/models_library/rest_base.py | 5 ++--- .../models-library/src/models_library/rest_ordering.py | 7 ++++--- packages/models-library/tests/test_rest_ordering.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/models-library/src/models_library/rest_base.py b/packages/models-library/src/models_library/rest_base.py index a6b24ef6382..797d8876680 100644 --- a/packages/models-library/src/models_library/rest_base.py +++ b/packages/models-library/src/models_library/rest_base.py @@ -1,4 +1,4 @@ -from pydantic import BaseModel, Extra +from pydantic import BaseModel, ConfigDict class RequestParameters(BaseModel): @@ -15,5 +15,4 @@ def as_params(self, **export_options) -> dict[str, str]: class StrictRequestParameters(RequestParameters): """Use a base class for context, path and query parameters""" - class Config: - extra = Extra.forbid # strict + model_config = ConfigDict(extra="forbid") diff --git a/packages/models-library/src/models_library/rest_ordering.py b/packages/models-library/src/models_library/rest_ordering.py index 3b355ae51ef..b042950c352 100644 --- a/packages/models-library/src/models_library/rest_ordering.py +++ b/packages/models-library/src/models_library/rest_ordering.py @@ -72,7 +72,8 @@ class _OrderBy(OrderBy): } ] }, - validate_assignment=True, # Necessary to run _check_ordering_field_and_map in defaults and assignments + # Necessary to run _check_ordering_field_and_map in defaults and assignments + validate_assignment=True, validate_default=True, ) @@ -91,9 +92,9 @@ def _check_ordering_field_and_map(cls, v): assert "json_schema_extra" in _OrderBy.model_config # nosec assert isinstance(_OrderBy.model_config["json_schema_extra"], dict) # nosec - assert isinstance( + assert isinstance( # nosec _OrderBy.model_config["json_schema_extra"]["examples"], list - ) # nosec + ) order_by_example = _OrderBy.model_config["json_schema_extra"]["examples"][0] order_by_example_json = json_dumps(order_by_example) assert _OrderBy.model_validate(order_by_example), "Example is invalid" # nosec diff --git a/packages/models-library/tests/test_rest_ordering.py b/packages/models-library/tests/test_rest_ordering.py index a495dc55721..a3f84bf0d2c 100644 --- a/packages/models-library/tests/test_rest_ordering.py +++ b/packages/models-library/tests/test_rest_ordering.py @@ -106,7 +106,7 @@ def test_ordering_query_model_class__fails_with_invalid_direction(): error = err_info.value.errors()[0] - assert error["type"] == "type_error.enum" + assert error["type"] == "enum" assert error["loc"] == ("order_by", "direction") @@ -137,7 +137,7 @@ def test_ordering_query_model_class__defaults(): error = err_info.value.errors()[0] assert error["loc"] == ("order_by", "field") - assert error["type"] == "value_error.missing" + assert error["type"] == "missing" def test_ordering_query_model_with_map():