From 9d27d52af9b852ac492f391fe69f5dd0a027c3cf Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Fri, 15 Nov 2024 14:13:24 +0100 Subject: backend/plugins: Throw error if E-Hentai response is missing 'gmetadata' It might be that we get a valid (maybe empty) response from the API, in which case we do not want to simply crash because we expect the 'gmetadata' field in the response. Instead, throw a proper ScrapeError for it. --- tests/plugins/scrapers/test_ehentai_api.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/plugins') diff --git a/tests/plugins/scrapers/test_ehentai_api.py b/tests/plugins/scrapers/test_ehentai_api.py index dd283e1..c746440 100644 --- a/tests/plugins/scrapers/test_ehentai_api.py +++ b/tests/plugins/scrapers/test_ehentai_api.py @@ -124,6 +124,22 @@ def test_raises_scrape_error_with_invalid_json(requests_mock, gen_comic): assert set(scraper.collect()) == set() +def test_raises_scrape_error_with_missing_field(requests_mock, gen_comic): + comic = next(gen_comic) + comic.url = "https://exhentai.org/g/1025913/fdaabef1a2" + + scraper = ehentai_api.EHentaiAPIScraper(comic) + + requests_mock.post(ehentai_api.API_URL, text="{}") + + assert scraper.is_available + assert scraper.id == 1025913 + assert scraper.token == "fdaabef1a2" + + with pytest.raises(ScrapeError, match="Response is missing 'gmetadata' field"): + assert set(scraper.collect()) == set() + + def test_raises_scrape_error_with_error_code(requests_mock, gen_comic): comic = next(gen_comic) comic.url = "https://exhentai.org/g/1025913/fdaabef1a2" -- cgit v1.2.3-2-gb3c3