feat(fc2a): add /api/settings/import and /api/system/stats endpoints
Settings GET returns the single-row ImportSettings DB record; PATCH does selective field updates (only known editable fields are applied; unknown keys silently ignored). System stats returns image/tag/storage counts, task status histogram, and the active batch summary in one shot for the Settings overview tab. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import pytest
|
||||
|
||||
from backend.app import create_app
|
||||
|
||||
|
||||
@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_import_settings_defaults(client):
|
||||
resp = await client.get("/api/settings/import")
|
||||
assert resp.status_code == 200
|
||||
body = await resp.get_json()
|
||||
# Defaults from the migration:
|
||||
assert body["min_width"] == 0
|
||||
assert body["min_height"] == 0
|
||||
assert body["skip_transparent"] is False
|
||||
assert body["transparency_threshold"] == 0.9
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_patch_import_settings(client):
|
||||
resp = await client.patch(
|
||||
"/api/settings/import",
|
||||
json={"min_width": 500, "skip_transparent": True, "transparency_threshold": 0.7},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
body = await resp.get_json()
|
||||
assert body["min_width"] == 500
|
||||
assert body["skip_transparent"] is True
|
||||
assert body["transparency_threshold"] == 0.7
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_patch_rejects_non_object(client):
|
||||
resp = await client.patch("/api/settings/import", json=[1, 2, 3])
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_system_stats_shape(client):
|
||||
resp = await client.get("/api/system/stats")
|
||||
assert resp.status_code == 200
|
||||
body = await resp.get_json()
|
||||
for key in ("total_images", "total_tags", "storage_bytes", "tasks", "active_batch"):
|
||||
assert key in body
|
||||
for status in ("pending", "queued", "processing", "complete", "skipped", "failed"):
|
||||
assert status in body["tasks"]
|
||||
Reference in New Issue
Block a user