Skip to content

Commit

Permalink
test: adapt tests for grouping by field feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-pl committed Dec 2, 2024
1 parent cfd3f83 commit 0dc3085
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/data/models/author_array_collection_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion tests/data/models/author_work_title_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
4 changes: 3 additions & 1 deletion tests/data/models/grouping_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Grouping model for RDFProxy testing."""

from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, Field


class GroupingSimpleModel(BaseModel):
Expand All @@ -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]
6 changes: 5 additions & 1 deletion tests/data/models/nested_grouping_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Nested grouping model for RDFProxy testing."""

from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, Field


class NestedGroupingSimpleModel(BaseModel):
Expand All @@ -11,12 +11,16 @@ class NestedGroupingSimpleModel(BaseModel):
class NestedGroupingNestedModel(BaseModel):
model_config = ConfigDict(group_by="y")

y: int = Field(exclude=True)

a: str
b: list[NestedGroupingSimpleModel]


class NestedGroupingComplexModel(BaseModel):
model_config = ConfigDict(group_by="a")

a: str = Field(exclude=True)

p: str
q: list[NestedGroupingNestedModel]
7 changes: 3 additions & 4 deletions tests/tests_mapper/test_sad_path_mapper_grouped_models.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand All @@ -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()

0 comments on commit 0dc3085

Please sign in to comment.