✨ Statut par service dans la Configuration: configure / teste / echec + endpoints de test pour tous les services
This commit is contained in:
1 parent
23132c6219
commit
3a75527135
9 files changed
+409
-59
No files matched your search
@@ -38,6 +38,109 @@ def test_radarr_connection() -> None:
|
||||
assert response.json()["version"] == "5.27.0"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_service_status_lifecycle() -> None:
|
||||
"""Statut par service: configured -> tested apres un test reussi, puis
|
||||
retour a configured quand la configuration change.
|
||||
|
||||
Utilise une URL distincte des autres tests: conf.json etant partage entre
|
||||
les tests, il faut garantir un reset du statut herite.
|
||||
"""
|
||||
respx.get("http://radarr-lifecycle:7878/api/v3/system/status").mock(
|
||||
return_value=Response(200, json={"version": "5.27.0"})
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
response = client.put(
|
||||
"/api/settings/radarr",
|
||||
json={"url": "http://radarr-lifecycle:7878", "api_key": "test-key"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
# Configure mais pas encore teste.
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["radarr"]["status"] == "configured"
|
||||
assert settings["qbittorrent"]["status"] in {"configured", "unconfigured"}
|
||||
|
||||
client.post("/api/settings/radarr/test")
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["radarr"]["status"] == "tested"
|
||||
assert settings["radarr"]["tested_version"] == "5.27.0"
|
||||
assert settings["radarr"]["tested_at"] is not None
|
||||
|
||||
# Le resultat du test est persiste dans conf.json.
|
||||
raw = json.loads(config_path().read_text(encoding="utf-8"))
|
||||
assert raw["radarr"]["test"]["ok"] is True
|
||||
assert raw["radarr"]["test"]["version"] == "5.27.0"
|
||||
|
||||
# Modifier l'URL invalide le statut de test.
|
||||
client.put(
|
||||
"/api/settings/radarr",
|
||||
json={"url": "http://radarr-alt:7878", "api_key": None},
|
||||
)
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["radarr"]["status"] == "configured"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_failed_test_marks_service_as_error() -> None:
|
||||
respx.get("http://radarr-fail:7878/api/v3/system/status").mock(
|
||||
return_value=Response(500, text="boom")
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
client.put(
|
||||
"/api/settings/radarr",
|
||||
json={"url": "http://radarr-fail:7878", "api_key": "test-key"},
|
||||
)
|
||||
response = client.post("/api/settings/radarr/test")
|
||||
assert response.status_code == 502
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["radarr"]["status"] == "error"
|
||||
assert settings["radarr"]["test_error"] is not None
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_sonarr_connection() -> None:
|
||||
"""Les services optionnels ont aussi un endpoint de test."""
|
||||
route = respx.get("http://sonarr:8989/api/v3/system/status").mock(
|
||||
return_value=Response(200, json={"version": "4.0.12"})
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
client.put(
|
||||
"/api/settings",
|
||||
json={"sonarr": {"url": "http://sonarr:8989", "api_key": "sonarr-key"}},
|
||||
)
|
||||
response = client.post("/api/settings/sonarr/test")
|
||||
settings = client.get("/api/settings").json()
|
||||
assert response.status_code == 200
|
||||
assert response.json()["version"] == "4.0.12"
|
||||
assert settings["sonarr"]["status"] == "tested"
|
||||
assert route.called
|
||||
assert "sonarr-key" in route.calls.last.request.headers["x-api-key"]
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_qbittorrent_status_lifecycle() -> None:
|
||||
respx.get("http://qbit-lifecycle:8080/api/v2/app/version").mock(
|
||||
return_value=Response(200, text="v5.0.2")
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
client.put(
|
||||
"/api/settings/qbittorrent",
|
||||
json={"url": "http://qbit-lifecycle:8080", "port": 8080},
|
||||
)
|
||||
assert client.post("/api/settings/qbittorrent/test").status_code == 200
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["qbittorrent"]["status"] == "tested"
|
||||
assert settings["qbittorrent"]["tested_version"] == "v5.0.2"
|
||||
|
||||
# Un nouvel enregistrement (URL differente) reinitialise le statut de test.
|
||||
client.put(
|
||||
"/api/settings/qbittorrent",
|
||||
json={"url": "http://qbit-alt:8080", "port": 8080},
|
||||
)
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["qbittorrent"]["status"] == "configured"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_scan_only_imports_iso_files() -> None:
|
||||
respx.get("http://radarr:7878/api/v3/movie?includeMovieFile=true").mock(
|
||||
|
||||
Reference in new issue
Block a user