a3bc98a53c
Post gains post_title_translated / description_translated / translated_source_lang / translation_engine_version / translated_at — filled by the translate sweep so viewing is instant. ImportSettings gains translation_enabled (OFF by default), interpreter_base_url (EMPTY — no default host; the operator points it at their own Interpreter proxy behind a reverse proxy) and translation_target_lang (en), exposed + validated via /settings/import. Migration 0083. Settings defaults + patch + validation test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CDgx8bQS5YrGRK76v8HUnM
182 lines
5.8 KiB
Python
182 lines
5.8 KiB
Python
import pytest
|
|
|
|
pytestmark = pytest.mark.integration
|
|
|
|
|
|
@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_translation_settings_defaults_and_patch(client):
|
|
# #143: translation is OFF by default with NO default host — the operator
|
|
# points it at their own Interpreter proxy and enables it.
|
|
body = await (await client.get("/api/settings/import")).get_json()
|
|
assert body["translation_enabled"] is False
|
|
assert body["interpreter_base_url"] == ""
|
|
assert body["translation_target_lang"] == "en"
|
|
|
|
ok = await client.patch("/api/settings/import", json={
|
|
"translation_enabled": True,
|
|
"interpreter_base_url": "http://interpreter.lan",
|
|
})
|
|
assert ok.status_code == 200
|
|
out = await ok.get_json()
|
|
assert out["translation_enabled"] is True
|
|
assert out["interpreter_base_url"] == "http://interpreter.lan"
|
|
|
|
# Type validation.
|
|
assert (await client.patch(
|
|
"/api/settings/import", json={"translation_enabled": "yes"})).status_code == 400
|
|
assert (await client.patch(
|
|
"/api/settings/import", json={"interpreter_base_url": 123})).status_code == 400
|
|
|
|
|
|
@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", "subscription_count", "tasks", "active_batch"):
|
|
assert key in body
|
|
for status in ("pending", "queued", "processing", "complete", "skipped", "failed"):
|
|
assert status in body["tasks"]
|
|
|
|
|
|
# --- FC-3d: scheduling knobs ----------------------------------------------
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_includes_scheduling_defaults(client):
|
|
resp = await client.get("/api/settings/import")
|
|
body = await resp.get_json()
|
|
assert body["download_schedule_default_seconds"] == 28800
|
|
assert body["download_event_retention_days"] == 90
|
|
assert body["download_failure_warning_threshold"] == 5
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_patch_scheduling_defaults(client):
|
|
resp = await client.patch("/api/settings/import", json={
|
|
"download_schedule_default_seconds": 7200,
|
|
"download_event_retention_days": 30,
|
|
"download_failure_warning_threshold": 3,
|
|
})
|
|
assert resp.status_code == 200
|
|
body = await resp.get_json()
|
|
assert body["download_schedule_default_seconds"] == 7200
|
|
assert body["download_event_retention_days"] == 30
|
|
assert body["download_failure_warning_threshold"] == 3
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_patch_rejects_below_min_interval(client):
|
|
resp = await client.patch(
|
|
"/api/settings/import",
|
|
json={"download_schedule_default_seconds": 30},
|
|
)
|
|
assert resp.status_code == 400
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_patch_rejects_above_max_interval(client):
|
|
resp = await client.patch(
|
|
"/api/settings/import",
|
|
json={"download_schedule_default_seconds": 90000},
|
|
)
|
|
assert resp.status_code == 400
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_patch_rejects_zero_retention_days(client):
|
|
resp = await client.patch(
|
|
"/api/settings/import",
|
|
json={"download_event_retention_days": 0},
|
|
)
|
|
assert resp.status_code == 400
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_patch_rejects_zero_failure_threshold(client):
|
|
resp = await client.patch(
|
|
"/api/settings/import",
|
|
json={"download_failure_warning_threshold": 0},
|
|
)
|
|
assert resp.status_code == 400
|
|
|
|
|
|
@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
|