From 4068a973922b7536173fc1ef2e2fd375777e0db8 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Fri, 3 Jul 2026 09:46:27 -0400 Subject: [PATCH] =?UTF-8?q?test(pixiv):=20fix=20downloader=20tests=20?= =?UTF-8?q?=E2=80=94=20skip=20validation=20on=20stub=20bytes,=20no=20media?= =?UTF-8?q?=20extraction=20in=20post-record=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stub payload is PNG bytes regardless of target extension, so the real validator quarantined the .jpg cases; and extracting the ugoira work hit the API seam of a fake session with no .post. Validation/quarantine plumbing stays covered by the Patreon downloader tests. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01CDgx8bQS5YrGRK76v8HUnM --- tests/test_pixiv_downloader.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/test_pixiv_downloader.py b/tests/test_pixiv_downloader.py index ea96992..636db77 100644 --- a/tests/test_pixiv_downloader.py +++ b/tests/test_pixiv_downloader.py @@ -67,9 +67,24 @@ def _post_and_media(work_id): raise AssertionError(f"no work {work_id} in fixture") +def _post_only(work_id): + """Normalized post WITHOUT media extraction — the write_post_record tests + don't need media, and extracting an ugoira would hit the API seam.""" + page = json.loads(_FIXTURE.read_text()) + for work in page["illusts"]: + if work["id"] == work_id: + return _client()._normalize(work) + raise AssertionError(f"no work {work_id} in fixture") + + def _downloader(tmp_path, session=None): + # validate=False: the stub payload is PNG bytes regardless of the target + # extension, so real validation would quarantine the .jpg cases. The + # validate/quarantine plumbing is BaseNativeDownloader's, covered by the + # Patreon downloader tests. return PixivDownloader( - tmp_path, session=session if session is not None else _FakeSession(), + tmp_path, validate=False, + session=session if session is not None else _FakeSession(), ) @@ -188,7 +203,7 @@ def test_own_session_carries_app_referer(tmp_path): def test_write_post_record_enriched(tmp_path): - post, _ = _post_and_media(111) + post = _post_only(111) dl = _downloader(tmp_path) outcome = dl.write_post_record(post, "artist-a") @@ -219,7 +234,7 @@ def test_write_post_record_enriched(tmp_path): def test_write_post_record_rating_r18(tmp_path): - post, _ = _post_and_media(222) + post = _post_only(222) dl = _downloader(tmp_path) outcome = dl.write_post_record(post, "artist-a") data = json.loads(outcome.path.read_text()) @@ -228,7 +243,7 @@ def test_write_post_record_rating_r18(tmp_path): def test_write_post_record_includes_ugoira_frames(tmp_path): - post, _ = _post_and_media(333) + post = _post_only(333) frames = [{"file": "000000.jpg", "delay": 90}] post["_work"]["_ugoira_frames"] = frames dl = _downloader(tmp_path)