-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test adaptions for QueryConstructor rewrite
- Loading branch information
Showing
24 changed files
with
436 additions
and
106 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Basic tests for rdfproxy.SPARQLModelAdapter pagination with ungrouped models.""" |
13 changes: 12 additions & 1 deletion
13
...data/parameters/count_query_parameters.py → ...structor/params/count_query_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
tests/tests_constructor/test_query_constructor_items_query.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
"""Basic tests for the QueryConstructor class.""" | ||
|
||
from typing import NamedTuple | ||
|
||
import pytest | ||
|
||
from pydantic import BaseModel | ||
from rdfproxy.constructor import QueryConstructor | ||
from rdfproxy.utils._types import ConfigDict | ||
from rdfproxy.utils.models import QueryParameters | ||
|
||
|
||
class UngroupedModel(BaseModel): | ||
x: int | ||
y: int | ||
|
||
|
||
class GroupedModel(BaseModel): | ||
model_config = ConfigDict(group_by="x") | ||
|
||
x: int | ||
y: list[int] | ||
|
||
|
||
class Expected(NamedTuple): | ||
count_query: str | ||
items_query: str | ||
|
||
|
||
class QueryConstructorParameters(NamedTuple): | ||
query: str | ||
query_parameters: QueryParameters | ||
model: type[BaseModel] | ||
|
||
expected: Expected | ||
|
||
|
||
parameters = [ | ||
# ungrouped | ||
QueryConstructorParameters( | ||
query="select * where {?s ?p ?o}", | ||
query_parameters=QueryParameters(), | ||
model=UngroupedModel, | ||
expected=Expected( | ||
count_query="select (count(*) as ?cnt) where {?s ?p ?o}", | ||
items_query="select * where {?s ?p ?o} order by ?s limit 100 offset 0", | ||
), | ||
), | ||
QueryConstructorParameters( | ||
query="select ?p ?o where {?s ?p ?o}", | ||
query_parameters=QueryParameters(), | ||
model=UngroupedModel, | ||
expected=Expected( | ||
count_query="select (count(*) as ?cnt) where {?s ?p ?o}", | ||
items_query="select ?p ?o where {?s ?p ?o} order by ?p limit 100 offset 0", | ||
), | ||
), | ||
QueryConstructorParameters( | ||
query="select * where {?s ?p ?o}", | ||
query_parameters=QueryParameters(page=2, size=2), | ||
model=UngroupedModel, | ||
expected=Expected( | ||
count_query="select (count(*) as ?cnt) where {?s ?p ?o}", | ||
items_query="select * where {?s ?p ?o} order by ?s limit 2 offset 2", | ||
), | ||
), | ||
# grouped | ||
QueryConstructorParameters( | ||
query="select * where {?x a ?y}", | ||
query_parameters=QueryParameters(), | ||
model=GroupedModel, | ||
expected=Expected( | ||
count_query="select (count(distinct ?x) as ?cnt) where {?x a ?y}", | ||
items_query="select * where {?x a ?y {select distinct ?x where {?x a ?y} order by ?x limit 100 offset 0} }", | ||
), | ||
), | ||
QueryConstructorParameters( | ||
query="select ?x ?y where {?x a ?y}", | ||
query_parameters=QueryParameters(), | ||
model=GroupedModel, | ||
expected=Expected( | ||
count_query="select (count(distinct ?x) as ?cnt) where {?x a ?y}", | ||
items_query="select ?x ?y where {?x a ?y {select distinct ?x where {?x a ?y} order by ?x limit 100 offset 0} }", | ||
), | ||
), | ||
QueryConstructorParameters( | ||
query="select ?x ?y where {?x a ?y}", | ||
query_parameters=QueryParameters(page=2, size=2), | ||
model=GroupedModel, | ||
expected=Expected( | ||
count_query="select (count(distinct ?x) as ?cnt) where {?x a ?y}", | ||
items_query="select ?x ?y where {?x a ?y {select distinct ?x where {?x a ?y} order by ?x limit 2 offset 2} }", | ||
), | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize(["query", "query_parameters", "model", "expected"], parameters) | ||
def test_query_constructor_items_query(query, query_parameters, model, expected): | ||
constructor = QueryConstructor( | ||
query=query, query_parameters=query_parameters, model=model | ||
) | ||
|
||
assert constructor.get_count_query() == expected.count_query | ||
assert constructor.get_items_query() == expected.items_query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 9 additions & 5 deletions
14
...eters/model_bindings_mapper_parameters.py → ...arams/model_bindings_mapper_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.