c03f17488c
CI / lint-and-test (push) Failing after 1m18s
Replace Syncthing as the product upload path with a share-target app and POST /api/jobs. Web UI live-polls job progress. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
"""Tests for job helpers (labels, inbox names, payloads)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from app import jobs, pipeline
|
|
|
|
|
|
def test_status_label_known_and_passthrough() -> None:
|
|
assert jobs.status_label("done") == "Fertig"
|
|
assert jobs.status_label("queued") == "Warteschlange"
|
|
assert jobs.status_label("weird") == "weird"
|
|
|
|
|
|
def test_stage_label_variant_progress() -> None:
|
|
label = jobs.stage_label("processing", "variant", {"current": 1, "total": 3})
|
|
assert label == "Variante 1/3"
|
|
assert jobs.stage_label("queued", None, None) == "Wartet auf Worker"
|
|
assert jobs.stage_label("processing", "rembg", None) == "Freistellen"
|
|
|
|
|
|
def test_make_inbox_filename_unique_and_safe() -> None:
|
|
a = jobs.make_inbox_filename("party.jpg")
|
|
b = jobs.make_inbox_filename("party.jpg")
|
|
assert a != b
|
|
assert a.endswith("_party.jpg")
|
|
assert "/" not in a
|
|
jpeg = jobs.make_inbox_filename("IMG_0001.JPEG")
|
|
assert jpeg.lower().endswith(".jpg")
|
|
fallback = jobs.make_inbox_filename("noext")
|
|
assert fallback.endswith("_noext.jpg")
|
|
|
|
|
|
def test_validate_job_id_rejects_paths() -> None:
|
|
with pytest.raises(jobs.JobIdError):
|
|
jobs.validate_job_id("../evil")
|
|
assert jobs.validate_job_id("foo@bar") == "foo_bar"
|
|
|
|
|
|
def test_summarize_job_includes_labels(data_dir: Path) -> None:
|
|
paths = pipeline.job_paths("event01")
|
|
pipeline.write_status(
|
|
paths,
|
|
"processing",
|
|
stage="rembg",
|
|
progress={"current": 0, "total": 3},
|
|
created_at="2026-01-01T00:00:00",
|
|
)
|
|
summary = jobs.summarize_job("event01")
|
|
assert summary["status_label"] == "Läuft"
|
|
assert summary["stage_label"] == "Freistellen"
|
|
assert summary["variant_count"] == 0
|