summaryrefslogtreecommitdiffstatshomepage
path: root/tests/plugins/scrapers/test_gallery_dl.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/plugins/scrapers/test_gallery_dl.py52
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