Files
FabledCurator/tests/test_api_suggestions.py
T
bvandeusen def967a1a8 refactor(dry-S1): hoist app/client test fixtures into conftest
Removed the app/client fixtures duplicated across 36 test files (two
variants: separate app + client(app), and a self-contained client() that
called create_app inline) and the now-unused create_app imports. Both
fixtures now live once in conftest.py. test_suggestions_bulk keeps its
import (builds the app inline in two tests); test_health drops its local
client + unused pytest_asyncio.

Net -415 lines.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 11:33:05 -04:00

78 lines
2.1 KiB
Python

import pytest
from backend.app.celery_app import celery
from backend.app.models import ImageRecord, TagKind
from backend.app.services.tag_service import TagService
pytestmark = pytest.mark.integration
@pytest.fixture(autouse=True)
def eager():
celery.conf.task_always_eager = True
yield
celery.conf.task_always_eager = False
async def _img(db, preds):
img = ImageRecord(
path="/images/s.jpg", sha256="s" * 64, size_bytes=1,
mime="image/jpeg", width=1, height=1,
origin="imported_filesystem", integrity_status="unknown",
tagger_predictions=preds,
)
db.add(img)
await db.commit()
return img
@pytest.mark.asyncio
async def test_get_suggestions(client, db):
img = await _img(
db, {"sword": {"category": "general", "confidence": 0.97}}
)
resp = await client.get(f"/api/images/{img.id}/suggestions")
assert resp.status_code == 200
body = await resp.get_json()
assert "general" in body["by_category"]
@pytest.mark.asyncio
async def test_accept_requires_tag_id(client, db):
img = await _img(db, {})
resp = await client.post(
f"/api/images/{img.id}/suggestions/accept", json={}
)
assert resp.status_code == 400
@pytest.mark.asyncio
async def test_accept_then_applied(client, db):
img = await _img(db, {})
tag = await TagService(db).find_or_create("AcceptMe", TagKind.character)
await db.commit()
resp = await client.post(
f"/api/images/{img.id}/suggestions/accept", json={"tag_id": tag.id}
)
assert resp.status_code == 204
@pytest.mark.asyncio
async def test_dismiss(client, db):
img = await _img(db, {})
tag = await TagService(db).find_or_create("DismissMe", TagKind.general)
await db.commit()
resp = await client.post(
f"/api/images/{img.id}/suggestions/dismiss", json={"tag_id": tag.id}
)
assert resp.status_code == 204
@pytest.mark.asyncio
async def test_alias_requires_fields(client, db):
img = await _img(db, {})
resp = await client.post(
f"/api/images/{img.id}/suggestions/alias", json={"alias_string": "x"}
)
assert resp.status_code == 400