✨ Rattrapage: renommage Radarr des films deja traites (unitaire + global, avant la v1.0.26)
This commit is contained in:
1 parent
b4cd2dc855
commit
aadf30bb07
4 files changed
+212
-16
No files matched your search
@@ -2,8 +2,10 @@ import errno
|
||||
import json
|
||||
import shutil
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import httpx
|
||||
import respx
|
||||
from fastapi.testclient import TestClient
|
||||
from httpx import Response
|
||||
@@ -467,3 +469,87 @@ def test_validate_survives_radarr_rescan_failure() -> None:
|
||||
assert body["status"] == "completed"
|
||||
assert body["rescan_warning"] is not None
|
||||
assert "mise à jour Radarr impossible" in body["rescan_warning"]
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_radarr_rename_only_for_processed_movies() -> None:
|
||||
"""Le renommage Radarr unitaire n'accepte que les films termines."""
|
||||
reset_state()
|
||||
create_film_folder()
|
||||
mock_radarr(str(settings.radarr_films_dir / FILM_FOLDER))
|
||||
with TestClient(app) as client:
|
||||
configure_radarr(client)
|
||||
client.post("/api/scans")
|
||||
movie_id = client.get("/api/movies").json()[0]["id"]
|
||||
|
||||
# Film non termine: refus.
|
||||
refused = client.post(f"/api/movies/{movie_id}/radarr-rename")
|
||||
assert refused.status_code == 409
|
||||
|
||||
client.post(f"/api/movies/{movie_id}/convert")
|
||||
wait_for_status(client, "validating")
|
||||
respx.post("http://radarr:7878/api/v3/command").mock(
|
||||
return_value=Response(201, json={"id": 1})
|
||||
)
|
||||
client.post(f"/api/movies/{movie_id}/validate")
|
||||
wait_for_status(client, "completed")
|
||||
|
||||
# Film termine: rescan + renommage Radarr.
|
||||
command_route = respx.post("http://radarr:7878/api/v3/command")
|
||||
response = client.post(f"/api/movies/{movie_id}/radarr-rename")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status"] == "completed"
|
||||
commands = [json.loads(call.request.content) for call in command_route.calls]
|
||||
# Deux appels de plus depuis le rattrapage: Rescan puis Rename.
|
||||
assert commands[-2:] == [
|
||||
{"name": "RescanMovie", "movieId": 10},
|
||||
{"name": "RenameMovie", "movieId": 10},
|
||||
]
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_radarr_rename_processed_bulk_reports_failures() -> None:
|
||||
"""Le renommage global traite tous les films termines et collecte les
|
||||
echecs sans interrompre la serie."""
|
||||
reset_state()
|
||||
create_film_folder()
|
||||
with SessionLocal() as db:
|
||||
db.add(
|
||||
IsoMovie(
|
||||
radarr_movie_id=10,
|
||||
radarr_movie_file_id=20,
|
||||
title="Film A",
|
||||
path="/films/a.iso",
|
||||
status="completed",
|
||||
last_seen_at=datetime(2026, 1, 1),
|
||||
)
|
||||
)
|
||||
db.add(
|
||||
IsoMovie(
|
||||
radarr_movie_id=11,
|
||||
radarr_movie_file_id=21,
|
||||
title="Film B",
|
||||
path="/films/b.iso",
|
||||
status="completed",
|
||||
last_seen_at=datetime(2026, 1, 1),
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
def command_response(request: httpx.Request) -> Response:
|
||||
body = json.loads(request.content)
|
||||
if body["movieId"] == 11:
|
||||
return Response(500, text="boom")
|
||||
return Response(201, json={"id": 1})
|
||||
|
||||
respx.post("http://radarr:7878/api/v3/command").mock(side_effect=command_response)
|
||||
with TestClient(app) as client:
|
||||
configure_radarr(client)
|
||||
result = client.post("/api/radarr/rename-processed")
|
||||
|
||||
assert result.status_code == 200
|
||||
body = result.json()
|
||||
assert body["renamed"] == 1
|
||||
assert len(body["failures"]) == 1
|
||||
assert body["failures"][0]["title"] == "Film B"
|
||||
assert "500" in body["failures"][0]["error"]
|
||||
Reference in new issue
Block a user