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
|
import pytest
from conftest import DB, Response
import hircine.plugins
from hircine.db.models import (
Artist,
Character,
Circle,
Page,
Tag,
World,
)
from hircine.scraper import Scraper
totals_fragment = """
fragment Totals on Statistics {
total {
archives
artists
characters
circles
comics
namespaces
scrapers
tags
worlds
images
pages
comic {
artists
characters
circles
tags
worlds
}
}
}
"""
@pytest.fixture
def query_statistics(execute):
query = """
query statistics {
statistics {
__typename
... Totals
}
}
"""
return execute(totals_fragment + query)
@pytest.mark.anyio
async def test_statistics_returns_totals(
gen_comic, gen_image, query_statistics, empty_plugins
):
comic = next(gen_comic)
await DB.add(comic)
await DB.add(Artist(name="foo"))
await DB.add(Character(name="foo"))
await DB.add(Circle(name="foo"))
await DB.add(World(name="foo"))
await DB.add(Tag(name="foo"))
image = next(gen_image)
await DB.add(image)
await DB.add(
Page(id=100, index=100, path="100.png", image=image, archive=comic.archive)
)
await DB.add(
Page(id=101, index=101, path="101.png", image=image, archive=comic.archive)
)
namespaces = set()
for tag in comic.tags:
namespaces.add(tag.namespace.id)
class MockScraper(Scraper):
name = "Scraper"
def scrape(self):
yield None
hircine.plugins.register_scraper("mock", MockScraper)
response = Response(await query_statistics())
response.assert_is("Statistics")
assert response.total["comics"] == 1
assert response.total["archives"] == 1
assert response.total["artists"] == len(comic.artists) + 1
assert response.total["characters"] == len(comic.characters) + 1
assert response.total["circles"] == len(comic.circles) + 1
assert response.total["worlds"] == len(comic.worlds) + 1
assert response.total["tags"] == len(comic.tags) + 1
assert response.total["namespaces"] == len(namespaces)
assert response.total["images"] == len(comic.pages) + 1
assert response.total["pages"] == len(comic.pages) + 2
assert response.total["scrapers"] == 1
assert response.total["comic"]["artists"] == len(comic.artists)
assert response.total["comic"]["characters"] == len(comic.characters)
assert response.total["comic"]["circles"] == len(comic.circles)
assert response.total["comic"]["tags"] == len(comic.tags)
assert response.total["comic"]["worlds"] == len(comic.worlds)
|