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