blob: f5bdb88f60d00f80e757cb89487d92bea4756698 (
plain) (
blame)
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
|
import json
import os
from zipfile import ZipFile
import pytest
import hircine.plugins.scrapers.gallery_dl
from hircine.plugins.scrapers.gallery_dl import GalleryDLScraper
from hircine.scraper.types import Title
class MockHandler:
source = "mock"
def scrape(self, data):
yield Title(data["title"])
@pytest.fixture
def archive_file(tmpdir):
file = os.path.join(tmpdir, "archive.zip")
with ZipFile(file, "x") as ziph:
ziph.writestr("info.json", json.dumps({"category": "mock", "title": "test"}))
yield file
def test_does_scrape(monkeypatch, archive_file, gen_comic):
comic = next(gen_comic)
comic.archive.path = archive_file
monkeypatch.setattr(
hircine.plugins.scrapers.gallery_dl, "HANDLERS", {"mock": MockHandler}
)
scraper = GalleryDLScraper(comic)
assert scraper.is_available
assert scraper.source == MockHandler.source
assert scraper.name == f"gallery-dl info.json ({MockHandler.source})"
assert set(scraper.collect()) == set([Title(value="test")])
def test_does_not_scrape_on_error(tmpdir, gen_comic):
comic = next(gen_comic)
comic.archive.path = os.path.join(tmpdir, "nonexistent.zip")
scraper = GalleryDLScraper(comic)
assert scraper.data == {}
assert not scraper.is_available
|