import pytest
from conftest import DB, Response
@pytest.fixture
def query_pagination(schema_execute):
query = """
query artists($pagination: Pagination) {
artists(pagination: $pagination) {
__typename
count
edges {
id
}
}
}
"""
async def _execute(pagination=None):
return await schema_execute(
query, {"pagination": pagination} if pagination else None
)
return _execute
@pytest.mark.parametrize(
"pagination,count,length",
[
(None, 4, 4),
({"items": 3, "page": 1}, 4, 3),
({"items": 3, "page": 2}, 4, 1),
({"items": 3, "page": 3}, 0, 0),
({"items": 10, "page": 1}, 4, 4),
({"items": 0, "page": 1}, 0, 0),
({"items": 2, "page": 0}, 0, 0),
({"items": -1, "page": 0}, 0, 0),
({"items": 0, "page": -1}, 0, 0),
],
ids=[
"is missing and lists all",
"lists first page",
"lists last page",
"lists none (no more items)",
"lists all",
"lists none (zero items)",
"lists none (page zero)",
"lists none (negative items)",
"lists none (negative page)",
],
)
@pytest.mark.anyio
async def test_pagination(query_pagination, gen_artist, pagination, count, length):
await DB.add_all(*gen_artist)
response = Response(await query_pagination(pagination))
response.assert_is("ArtistFilterResult")
assert response.count == count
assert isinstance((response.edges), list)
assert len(response.edges) == length