aa4cc7c629
Rename returns 409 on collision (frontend shows FC-2c merge hint), 400 on empty. ml_admin: GET/PATCH settings (thresholds + min_reference; model versions read-only here), POST backfill / recompute-centroids returning 202 + celery task id. Tests integration-marked, eager Celery. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
import pytest
|
|
|
|
from backend.app import create_app
|
|
from backend.app.celery_app import celery
|
|
from backend.app.models import 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
|
|
|
|
|
|
@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_get_and_patch_settings(client):
|
|
resp = await client.get("/api/ml/settings")
|
|
assert resp.status_code == 200
|
|
body = await resp.get_json()
|
|
assert body["suggestion_threshold_general"] == pytest.approx(0.95)
|
|
|
|
resp = await client.patch(
|
|
"/api/ml/settings", json={"suggestion_threshold_general": 0.90}
|
|
)
|
|
assert resp.status_code == 200
|
|
assert (await resp.get_json())["suggestion_threshold_general"] == pytest.approx(0.90)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_backfill_and_recompute_trigger(client):
|
|
r1 = await client.post("/api/ml/backfill")
|
|
assert r1.status_code == 202
|
|
r2 = await client.post("/api/ml/recompute-centroids")
|
|
assert r2.status_code == 202
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_rename_tag(client, db):
|
|
tag = await TagService(db).find_or_create("oldname", TagKind.character)
|
|
await db.commit()
|
|
resp = await client.patch(f"/api/tags/{tag.id}", json={"name": "New Name"})
|
|
assert resp.status_code == 200
|
|
assert (await resp.get_json())["name"] == "New Name"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_rename_collision_409(client, db):
|
|
svc = TagService(db)
|
|
await svc.find_or_create("Taken", TagKind.character)
|
|
other = await svc.find_or_create("Mover", TagKind.character)
|
|
await db.commit()
|
|
resp = await client.patch(f"/api/tags/{other.id}", json={"name": "Taken"})
|
|
assert resp.status_code == 409
|