From 0dc3085f60cbef048849020fb1cef4f03cbcd6ff Mon Sep 17 00:00:00 2001 From: Lukas Plank Date: Mon, 2 Dec 2024 14:15:11 +0100 Subject: [PATCH] test: adapt tests for grouping by field feature --- tests/data/models/author_array_collection_model.py | 4 ++-- tests/data/models/author_work_title_model.py | 2 +- tests/data/models/grouping_model.py | 4 +++- tests/data/models/nested_grouping_model.py | 6 +++++- tests/tests_mapper/test_sad_path_mapper_grouped_models.py | 7 +++---- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/data/models/author_array_collection_model.py b/tests/data/models/author_array_collection_model.py index d1d7a3f..131a957 100644 --- a/tests/data/models/author_array_collection_model.py +++ b/tests/data/models/author_array_collection_model.py @@ -5,14 +5,14 @@ class Work(BaseModel): - model_config = ConfigDict(group_by="work_name") + model_config = ConfigDict(group_by="name") name: Annotated[str, SPARQLBinding("work_name")] viafs: Annotated[list[str], SPARQLBinding("viaf")] class Author(BaseModel): - model_config = ConfigDict(group_by="nameLabel") + model_config = ConfigDict(group_by="surname") gnd: str surname: Annotated[str, SPARQLBinding("nameLabel")] diff --git a/tests/data/models/author_work_title_model.py b/tests/data/models/author_work_title_model.py index d69eb2f..f934314 100644 --- a/tests/data/models/author_work_title_model.py +++ b/tests/data/models/author_work_title_model.py @@ -18,7 +18,7 @@ class Work(BaseModel): class Author(BaseModel): - model_config = ConfigDict(group_by="author") + model_config = ConfigDict(group_by="name") name: Annotated[str, SPARQLBinding("author")] works: list[Work] diff --git a/tests/data/models/grouping_model.py b/tests/data/models/grouping_model.py index 35d21a0..9289f92 100644 --- a/tests/data/models/grouping_model.py +++ b/tests/data/models/grouping_model.py @@ -1,6 +1,6 @@ """Grouping model for RDFProxy testing.""" -from pydantic import BaseModel, ConfigDict +from pydantic import BaseModel, ConfigDict, Field class GroupingSimpleModel(BaseModel): @@ -16,5 +16,7 @@ class GroupingNestedModel(BaseModel): class GroupingComplexModel(BaseModel): model_config = ConfigDict(group_by="x") + x: int = Field(exclude=True) + p: str q: list[GroupingNestedModel] diff --git a/tests/data/models/nested_grouping_model.py b/tests/data/models/nested_grouping_model.py index 8b88bfa..89fd0d3 100644 --- a/tests/data/models/nested_grouping_model.py +++ b/tests/data/models/nested_grouping_model.py @@ -1,6 +1,6 @@ """Nested grouping model for RDFProxy testing.""" -from pydantic import BaseModel, ConfigDict +from pydantic import BaseModel, ConfigDict, Field class NestedGroupingSimpleModel(BaseModel): @@ -11,6 +11,8 @@ class NestedGroupingSimpleModel(BaseModel): class NestedGroupingNestedModel(BaseModel): model_config = ConfigDict(group_by="y") + y: int = Field(exclude=True) + a: str b: list[NestedGroupingSimpleModel] @@ -18,5 +20,7 @@ class NestedGroupingNestedModel(BaseModel): class NestedGroupingComplexModel(BaseModel): model_config = ConfigDict(group_by="a") + a: str = Field(exclude=True) + p: str q: list[NestedGroupingNestedModel] diff --git a/tests/tests_mapper/test_sad_path_mapper_grouped_models.py b/tests/tests_mapper/test_sad_path_mapper_grouped_models.py index b4a54d8..07f0e90 100644 --- a/tests/tests_mapper/test_sad_path_mapper_grouped_models.py +++ b/tests/tests_mapper/test_sad_path_mapper_grouped_models.py @@ -1,10 +1,9 @@ -import pytest - from pydantic import BaseModel, ConfigDict +import pytest from rdfproxy import ModelBindingsMapper from rdfproxy.utils._exceptions import ( + InvalidGroupingKeyException, MissingModelConfigException, - UnboundGroupingKeyException, ) @@ -24,5 +23,5 @@ def test_sad_path_adapter_missing_grouping_config(): def test_sad_path_adapter_missing_grouping_value(): - with pytest.raises(UnboundGroupingKeyException): + with pytest.raises(InvalidGroupingKeyException): ModelBindingsMapper(ModelMissingGroupByValue, {"x": 1}).get_models()