Files
livef12rocks/tests/test_main.py
T
Frank Schwenk b09f90bfcc
CI / lint-and-test (pull_request) Failing after 9s
fix: lock meta RMW and harden concurrent remix paths
Prevent worker/web clobbering of meta variants via flock and merge-by-id,
make filter timeouts thread-local, harden job-id/stem sanitization, migrate
TemplateResponse API, and remove the compare-bg experiment.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-18 17:44:15 +02:00

53 lines
1.5 KiB
Python

"""Tests for FastAPI routes and validation."""
from __future__ import annotations
from pathlib import Path
import pytest
from app import config, pipeline
from app.main import _safe_job_file, _validate_job_id, app
from fastapi import HTTPException
from fastapi.testclient import TestClient
@pytest.fixture
def client(data_dir: Path) -> TestClient:
return TestClient(app)
def test_validate_job_id_sanitizes_input() -> None:
assert _validate_job_id("foo@bar") == "foo_bar"
assert _validate_job_id("photo01") == "photo01"
def test_validate_job_id_rejects_path_like() -> None:
with pytest.raises(HTTPException) as exc:
_validate_job_id("a/b")
assert exc.value.status_code == 400
with pytest.raises(HTTPException):
_validate_job_id("../evil")
with pytest.raises(HTTPException):
_validate_job_id("")
def test_safe_job_file_rejects_wrong_prefix(data_dir: Path) -> None:
stem = "photo01"
paths = pipeline.job_paths(stem)
paths.variants.mkdir(parents=True, exist_ok=True)
target = paths.variants / f"{stem}_v1.png"
target.write_bytes(b"x")
with pytest.raises(HTTPException):
_safe_job_file(stem, "other_v1.png")
def test_index_empty(client: TestClient) -> None:
response = client.get("/")
assert response.status_code == 200
assert config.SITE_TITLE in response.text
def test_job_not_found(client: TestClient) -> None:
response = client.get("/jobs/does-not-exist")
assert response.status_code == 404