From d1d654ebac2d51e3841675faeb56480e440f622f Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Tue, 5 Mar 2024 18:08:09 +0100 Subject: Initial commit --- tests/api/test_page.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/api/test_page.py (limited to 'tests/api/test_page.py') diff --git a/tests/api/test_page.py b/tests/api/test_page.py new file mode 100644 index 0000000..debd69a --- /dev/null +++ b/tests/api/test_page.py @@ -0,0 +1,39 @@ +from datetime import datetime, timezone + +import pytest +from conftest import DB +from hircine.api.types import Page +from hircine.db.models import Archive + + +@pytest.mark.anyio +async def test_page(gen_page): + pages = list(gen_page) + images = [p.image for p in pages] + + # persist images and pages in database by binding them to a throwaway + # archive + archive = await DB.add( + Archive( + hash="339e3a32e5648fdeb2597f05cb2e1ef6", + path="some/archive.zip", + size=78631597, + mtime=datetime(1999, 12, 27, tzinfo=timezone.utc), + cover=images[0], + pages=pages, + page_count=len(pages), + ) + ) + + assert len(archive.pages) == len(pages) + + page_iter = iter(pages) + image_iter = iter(images) + for page in [Page(p) for p in archive.pages]: + matching_page = next(page_iter) + matching_image = next(image_iter) + + assert page.id == matching_page.id + assert page.comic_id is None + assert page.image.id == matching_image.id + assert page.path == matching_page.path -- cgit v1.2.3-2-gb3c3