1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
from functools import partial
import pytest
from conftest import DB, Response
from hircine.db.models import Namespace, Tag
@pytest.fixture
def query_comic_tags(schema_execute):
query = """
query comicTags($forFilter: Boolean) {
comicTags(forFilter: $forFilter) {
edges {
__typename
id
name
}
count
}
}
"""
def wrapper(q):
async def _execute(for_filter=False):
return await schema_execute(q, {"forFilter": for_filter})
return _execute
return wrapper(query)
def build_item(namespace, tag):
nid, tid = "", ""
nname, tname = "", ""
if namespace:
nid, nname = namespace.id, namespace.name
if tag:
tid, tname = tag.id, tag.name
item = {
"__typename": "ComicTag",
"id": f"{nid}:{tid}",
"name": f"{nname}:{tname}",
}
return item
@pytest.mark.anyio
async def test_query_comic_tags_cross(query_comic_tags):
ns_foo = Namespace(id=1, name="foo")
ns_bar = Namespace(id=2, name="bar")
tag_qoo = Tag(id=1, name="qoo", namespaces=[ns_foo, ns_bar])
tag_qar = Tag(id=2, name="qar", namespaces=[ns_foo, ns_bar])
await DB.add_all(ns_foo, ns_bar)
await DB.add_all(tag_qoo, tag_qar)
builder = partial(build_item)
response = Response(await query_comic_tags())
assert response.data["edges"] == [
builder(ns_bar, tag_qar),
builder(ns_bar, tag_qoo),
builder(ns_foo, tag_qar),
builder(ns_foo, tag_qoo),
]
@pytest.mark.anyio
async def test_query_comic_tags_restricted_namespace(query_comic_tags):
ns_foo = Namespace(id=1, name="foo")
ns_bar = Namespace(id=2, name="bar")
tag_qoo = Tag(id=1, name="qoo", namespaces=[ns_bar])
tag_qar = Tag(id=2, name="qar", namespaces=[ns_foo])
await DB.add_all(ns_foo, ns_bar)
await DB.add_all(tag_qoo, tag_qar)
builder = partial(build_item)
response = Response(await query_comic_tags())
assert response.data["edges"] == [
builder(ns_bar, tag_qoo),
builder(ns_foo, tag_qar),
]
@pytest.mark.anyio
async def test_query_comic_tag_matchers_cross(query_comic_tags):
ns_foo = Namespace(id=1, name="foo")
ns_bar = Namespace(id=2, name="bar")
tag_qoo = Tag(id=1, name="qoo", namespaces=[ns_foo, ns_bar])
tag_qar = Tag(id=2, name="qar", namespaces=[ns_foo, ns_bar])
await DB.add_all(ns_foo, ns_bar, tag_qoo, tag_qar)
builder = partial(build_item)
response = Response(await query_comic_tags(for_filter=True))
assert response.data["edges"] == [
builder(ns_bar, None),
builder(ns_foo, None),
builder(None, tag_qar),
builder(None, tag_qoo),
builder(ns_bar, tag_qar),
builder(ns_bar, tag_qoo),
builder(ns_foo, tag_qar),
builder(ns_foo, tag_qoo),
]
@pytest.mark.anyio
async def test_query_comic_tag_matchers_restricted_namespace(query_comic_tags):
ns_foo = Namespace(id=1, name="foo")
ns_bar = Namespace(id=2, name="bar")
tag_qoo = Tag(id=1, name="qoo", namespaces=[ns_bar])
tag_qar = Tag(id=2, name="qar", namespaces=[ns_foo])
await DB.add_all(ns_foo, ns_bar, tag_qoo, tag_qar)
builder = partial(build_item)
response = Response(await query_comic_tags(for_filter=True))
assert response.data["edges"] == [
builder(ns_bar, None),
builder(ns_foo, None),
builder(None, tag_qar),
builder(None, tag_qoo),
builder(ns_bar, tag_qoo),
builder(ns_foo, tag_qar),
]
|