summaryrefslogtreecommitdiffstatshomepage
path: root/tests/api/test_sort.py
diff options
context:
space:
mode:
authorWolfgang Müller2025-02-20 14:27:14 +0100
committerWolfgang Müller2025-02-20 19:51:04 +0100
commitc6bf35aea63969b90463d6e70cb02ed61e4e3270 (patch)
tree1e650689385e23b204754dd1bba156654f95612d /tests/api/test_sort.py
parent39ecba8f6c5a2bc3b4f0629aecac99560c270539 (diff)
downloadhircine-c6bf35aea63969b90463d6e70cb02ed61e4e3270.tar.gz
Add remaining association count sort options
Now that we have all association counts mapped to their respective models we can easily allow sorting on them as well.
Diffstat (limited to 'tests/api/test_sort.py')
-rw-r--r--tests/api/test_sort.py75
1 files changed, 74 insertions, 1 deletions
diff --git a/tests/api/test_sort.py b/tests/api/test_sort.py
index 404e3d6..65a4990 100644
--- a/tests/api/test_sort.py
+++ b/tests/api/test_sort.py
@@ -1,7 +1,7 @@
import pytest
from conftest import DB, Response
-from hircine.db.models import Namespace
+from hircine.db.models import Namespace, Tag
@pytest.fixture
@@ -23,6 +23,24 @@ def query_comic_sort(execute_sort):
@pytest.fixture
+def query_artist_sort(execute_sort):
+ query = """
+ query artists($sort: ArtistSortInput) {
+ artists(sort: $sort) {
+ __typename
+ count
+ edges {
+ id
+ name
+ }
+ }
+ }
+ """
+
+ return execute_sort(query)
+
+
+@pytest.fixture
def query_namespace_sort(execute_sort):
query = """
query namespaces($sort: NamespaceSortInput) {
@@ -88,6 +106,31 @@ async def test_query_comics_sort_tag_count(gen_comic, query_comic_sort, sort, re
assert ids == [edge["id"] for edge in response.edges]
+@pytest.mark.parametrize(
+ "sort,reverse,expect",
+ [
+ ({"on": "COMIC_COUNT"}, False, [2, 3, 1, 4]),
+ ({"on": "COMIC_COUNT", "direction": "DESCENDING"}, True, [1, 4, 2, 3]),
+ ({"on": "COMIC_COUNT", "direction": "ASCENDING"}, False, [2, 3, 1, 4]),
+ ],
+ ids=[
+ "ascending (default)",
+ "descending",
+ "ascending",
+ ],
+)
+@pytest.mark.anyio
+async def test_query_artists_sort_comic_count(
+ gen_comic, query_artist_sort, sort, reverse, expect
+):
+ await DB.add_all(*gen_comic)
+
+ response = Response(await query_artist_sort(sort))
+ response.assert_is("ArtistFilterResult")
+
+ assert expect == [edge["id"] for edge in response.edges]
+
+
@pytest.mark.anyio
async def test_query_comics_sort_random(gen_comic, query_comic_sort):
comics = await DB.add_all(*gen_comic)
@@ -136,3 +179,33 @@ async def test_query_namespace_sort_sort_name(query_namespace_sort):
response.assert_is("NamespaceFilterResult")
assert [edge["name"] for edge in response.edges] == ["two", "one"]
+
+@pytest.mark.parametrize(
+ "sort,reverse,expect",
+ [
+ ({"on": "TAG_COUNT"}, False, [2, 1]),
+ ({"on": "TAG_COUNT", "direction": "DESCENDING"}, True, [1, 2]),
+ ({"on": "TAG_COUNT", "direction": "ASCENDING"}, False, [2, 1]),
+ ],
+ ids=[
+ "ascending (default)",
+ "descending",
+ "ascending",
+ ],
+)
+@pytest.mark.anyio
+async def test_query_namespace_sort_tag_count(
+ gen_comic, query_namespace_sort, sort, reverse, expect
+):
+ namespace_foo = Namespace(id=1, name="foo")
+ namespace_bar = Namespace(id=2, name="bar")
+
+ tag_foo = Tag(id=1, name="foo", namespaces=[namespace_foo])
+ tag_bar = Tag(id=2, name="bar", namespaces=[namespace_foo, namespace_bar])
+
+ await DB.add_all(tag_foo, tag_bar)
+
+ response = Response(await query_namespace_sort(sort))
+ response.assert_is("NamespaceFilterResult")
+
+ assert expect == [edge["id"] for edge in response.edges]