c37a3c9b55
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
108 lines
3.1 KiB
Python
108 lines
3.1 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"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_system_stats_integrity_counts(client, db):
|
|
from backend.app.models import ImageRecord
|
|
|
|
base = "stats_" + "0" * 56
|
|
for i, status in enumerate(
|
|
["ok", "ok", "corrupt", "failed_verification"]
|
|
):
|
|
db.add(ImageRecord(
|
|
path=f"/images/i/{i}.jpg", sha256=base + f"{i:02d}",
|
|
size_bytes=1, mime="image/jpeg", width=1, height=1,
|
|
origin="imported_filesystem", integrity_status=status,
|
|
))
|
|
await db.commit()
|
|
|
|
resp = await client.get("/api/system/stats")
|
|
assert resp.status_code == 200
|
|
body = await resp.get_json()
|
|
integ = body["integrity"]
|
|
assert integ["ok"] >= 2
|
|
assert integ["corrupt"] >= 1
|
|
assert integ["failed_verification"] >= 1
|
|
assert "unknown" in integ
|