diff options
author | Wolfgang Müller | 2024-03-05 18:08:09 +0100 |
---|---|---|
committer | Wolfgang Müller | 2024-03-05 19:25:59 +0100 |
commit | d1d654ebac2d51e3841675faeb56480e440f622f (patch) | |
tree | 56ef123c1a15a10dfd90836e4038e27efde950c6 /tests/api/test_page.py | |
download | hircine-0.1.0.tar.gz |
Initial commit0.1.0
Diffstat (limited to '')
-rw-r--r-- | tests/api/test_page.py | 39 |
1 files changed, 39 insertions, 0 deletions
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 |