Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️♻️ Fix/test models #6758

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/models-library/src/models_library/rest_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, Extra
from pydantic import BaseModel, ConfigDict


class RequestParameters(BaseModel):
Expand All @@ -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")
7 changes: 4 additions & 3 deletions packages/models-library/src/models_library/rest_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/models-library/tests/test_rest_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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():
Expand Down
Loading