feat: optimize Sascha Emby edge (tests/test_app.py)

This commit is contained in:
sascha 2026-09-05 13:13:19 +02:00
parent 07d3e019e2
commit 3c3bc0fcda

View file

@ -43,7 +43,7 @@ def test_health_exposes_current_version():
with TestClient(app.app) as client:
response = client.get("/health")
assert response.status_code == 200
assert response.json()["version"] == app.VERSION == "2.4.0"
assert response.json()["version"] == app.VERSION == "2.4.1"
def test_media_handoff_proxies_strict_category_contract(monkeypatch):
@ -1370,3 +1370,31 @@ def test_sascha_media_path_benchmark_returns_both_fixed_routes(monkeypatch):
assert response.status_code == 200
assert response.json()["direction"] == "emby-sascha_to_hetzner"
assert set(response.json()["results"]) == {"legacy_node6", "direct_wg_media"}
def test_sascha_media_edge_optimize_is_dry_run_by_default(monkeypatch):
monkeypatch.setattr(app, "_optimize_sascha_media_edge", lambda: (_ for _ in ()).throw(AssertionError("dry-run must not mutate")))
with TestClient(app.app) as client:
response = client.post("/media/edge/sascha/optimize", headers={"Authorization": "Bearer test-token"}, json={})
assert response.status_code == 200
assert response.json()["protocols"] == ["h1", "h2"]
assert response.json()["upstream"] == "10.11.13.3:8096"
def test_sascha_media_edge_optimize_requires_confirmation(monkeypatch):
monkeypatch.setattr(app, "_optimize_sascha_media_edge", lambda: (_ for _ in ()).throw(AssertionError("must not mutate")))
with TestClient(app.app) as client:
response = client.post("/media/edge/sascha/optimize", headers={"Authorization": "Bearer test-token"}, json={"dry_run": False})
assert response.status_code == 400
def test_sascha_media_edge_optimize_applies_fixed_safe_result(monkeypatch):
monkeypatch.setattr(app, "_optimize_sascha_media_edge", lambda: {"status": "optimized", "upstream": "10.11.13.3:8096", "protocols": ["h1", "h2"], "backup": "/app-config/caddy/backup", "sha256": "a" * 64})
with TestClient(app.app) as client:
response = client.post(
"/media/edge/sascha/optimize",
headers={"Authorization": "Bearer test-token"},
json={"dry_run": False, "confirmation": "OPTIMIZE_TV_SASCHA_LUTZ_DE"},
)
assert response.status_code == 200
assert response.json()["status"] == "optimized"