diff options
author | Wolfgang Müller | 2024-11-14 23:22:58 +0100 |
---|---|---|
committer | Wolfgang Müller | 2024-11-14 23:22:58 +0100 |
commit | a495162ab6d0bf324c300eca398532ee397cf9a1 (patch) | |
tree | 4f415b8770c4c697a3d948da0eb729370aafd595 /tests/plugins/scrapers/test_gallery_dl.py | |
parent | 47d464fbfc1dd4174c4f0ab39268297c14b972a3 (diff) | |
download | hircine-a495162ab6d0bf324c300eca398532ee397cf9a1.tar.gz |
backend/tests: Add tests for gallery_dl scrapers
Diffstat (limited to 'tests/plugins/scrapers/test_gallery_dl.py')
-rw-r--r-- | tests/plugins/scrapers/test_gallery_dl.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/plugins/scrapers/test_gallery_dl.py b/tests/plugins/scrapers/test_gallery_dl.py new file mode 100644 index 0000000..b4e7a4a --- /dev/null +++ b/tests/plugins/scrapers/test_gallery_dl.py @@ -0,0 +1,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, monkeypatch, 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 |