9ef5e5047d
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
83 lines
2.3 KiB
Python
83 lines
2.3 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
|
|
|
|
|
|
@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_import_settings_phash_threshold_default(client):
|
|
resp = await client.get("/api/settings/import")
|
|
assert resp.status_code == 200
|
|
assert (await resp.get_json())["phash_threshold"] == 10
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_patch_phash_threshold(client):
|
|
resp = await client.patch(
|
|
"/api/settings/import", json={"phash_threshold": 4}
|
|
)
|
|
assert resp.status_code == 200
|
|
assert (await resp.get_json())["phash_threshold"] == 4
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_patch_phash_threshold_rejects_negative(client):
|
|
resp = await client.patch(
|
|
"/api/settings/import", json={"phash_threshold": -1}
|
|
)
|
|
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"]
|