46338a1f2e
Allowlist: list-all, get-one (404 if not listed), PATCH threshold (range-validated), DELETE. Aliases: list-all (with canonical name), create (idempotent, 201), DELETE by (string, category). Tests integration-marked. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
import pytest
|
|
|
|
from backend.app import create_app
|
|
from backend.app.models import TagKind
|
|
from backend.app.services.tag_service import TagService
|
|
|
|
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
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_list_delete(client, db):
|
|
tag = await TagService(db).find_or_create("Canon", TagKind.character)
|
|
await db.commit()
|
|
|
|
resp = await client.post(
|
|
"/api/aliases",
|
|
json={
|
|
"alias_string": "model_name",
|
|
"alias_category": "character",
|
|
"canonical_tag_id": tag.id,
|
|
},
|
|
)
|
|
assert resp.status_code == 201
|
|
|
|
resp = await client.get("/api/aliases")
|
|
body = await resp.get_json()
|
|
assert any(
|
|
a["alias_string"] == "model_name"
|
|
and a["canonical_tag_name"] == "Canon"
|
|
for a in body
|
|
)
|
|
|
|
resp = await client.delete("/api/aliases/model_name/character")
|
|
assert resp.status_code == 204
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_requires_fields(client):
|
|
resp = await client.post("/api/aliases", json={"alias_string": "x"})
|
|
assert resp.status_code == 400
|