Files
FabledCurator/tests/test_api_series.py
T
2026-05-16 23:35:12 -04:00

73 lines
1.9 KiB
Python

import pytest
from backend.app import create_app
pytestmark = pytest.mark.integration
@pytest.fixture
async def app():
return create_app()
@pytest.fixture
async def client(app):
async with app.test_client() as c:
yield c
async def _series(client, name="Vol"):
r = await client.post("/api/tags", json={"name": name, "kind": "series"})
return (await r.get_json())["id"]
@pytest.mark.asyncio
async def test_pages_404_for_non_series(client):
r = await client.post("/api/tags", json={"name": "g", "kind": "general"})
gid = (await r.get_json())["id"]
resp = await client.get(f"/api/series/{gid}/pages")
assert resp.status_code == 404
@pytest.mark.asyncio
async def test_pages_empty_shape(client):
sid = await _series(client, "Empty")
resp = await client.get(f"/api/series/{sid}/pages")
assert resp.status_code == 200
body = await resp.get_json()
assert body["series"]["id"] == sid
assert body["pages"] == []
@pytest.mark.asyncio
async def test_add_requires_ids(client):
sid = await _series(client, "NoIds")
resp = await client.post(f"/api/series/{sid}/pages", json={})
assert resp.status_code == 400
@pytest.mark.asyncio
async def test_add_over_cap_400(client):
sid = await _series(client, "Cap")
resp = await client.post(
f"/api/series/{sid}/pages",
json={"image_ids": list(range(1, 502))},
)
assert resp.status_code == 400
@pytest.mark.asyncio
async def test_reorder_mismatch_400(client):
sid = await _series(client, "Re")
resp = await client.post(
f"/api/series/{sid}/reorder", json={"image_ids": [1, 2, 3]}
)
assert resp.status_code == 400
@pytest.mark.asyncio
async def test_cover_requires_image_id(client):
sid = await _series(client, "Cov")
resp = await client.post(f"/api/series/{sid}/cover", json={})
assert resp.status_code == 400