🚑 Reparation du lien MKV: detection du lien casse (brut intact) et recration au nom attendu par Radarr + rescan
This commit is contained in:
1 parent
cbf72df09a
commit
8325af2b01
6 files changed
+223
No files matched your search
@@ -829,3 +829,90 @@ def test_delete_download_iso_manual_with_safety_guards() -> None:
|
||||
# La fiche ne porte plus le tag.
|
||||
fiche = client.get(f"/api/files/{ids['Film Telecharge']}").json()
|
||||
assert fiche["iso_to_delete"] is False
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_repair_link_recreates_hardlink_with_radarr_name() -> None:
|
||||
"""Lien casse (brut present, lien absent): la reparation recree un lien
|
||||
dur au nom attendu par Radarr, meme inode, et rescanne Radarr."""
|
||||
reset_state()
|
||||
with SessionLocal() as db:
|
||||
movie = IsoMovie(
|
||||
radarr_movie_id=10,
|
||||
radarr_movie_file_id=20,
|
||||
title="Film Casse",
|
||||
year=2020,
|
||||
path=str(settings.radarr_films_dir / "Film Casse (2020)" / "FILM.iso"),
|
||||
status="completed",
|
||||
last_seen_at=datetime(2026, 1, 1),
|
||||
)
|
||||
db.add(movie)
|
||||
db.commit()
|
||||
movie_id = movie.id
|
||||
# MKV brut present dans le dossier de travail, dossier du film vide.
|
||||
brut = settings.downloads_dir / "Film Casse 2020" / "Film Casse (2020).mkv"
|
||||
brut.parent.mkdir(parents=True, exist_ok=True)
|
||||
brut.write_text("donnees du mkv")
|
||||
film_folder = settings.films_dir / "Film Casse (2020)"
|
||||
film_folder.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Radarr connait le nom attendu (apres renommage Media Management).
|
||||
respx.get("http://radarr:7878/api/v3/movie/10").mock(
|
||||
return_value=Response(
|
||||
200,
|
||||
json={"id": 10, "movieFile": {
|
||||
"id": 99,
|
||||
"path": "/movies/Film Casse (2020)/Film.Casse.2020.1080p.BluRay.mkv",
|
||||
}},
|
||||
)
|
||||
)
|
||||
rescan_route = respx.post("http://radarr:7878/api/v3/command").mock(
|
||||
return_value=Response(201, json={"id": 1})
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
configure_radarr(client)
|
||||
# La fiche detecte le lien casse.
|
||||
fiche = client.get(f"/api/files/{movie_id}").json()
|
||||
assert fiche["link_broken"] is True
|
||||
|
||||
repair = client.post(f"/api/movies/{movie_id}/repair-link")
|
||||
assert repair.status_code == 200
|
||||
message = repair.json()["message"]
|
||||
assert "Lien du MKV recréé" in message
|
||||
|
||||
# Le lien porte le nom attendu par Radarr et partage l'inode du brut.
|
||||
linked = film_folder / "Film.Casse.2020.1080p.BluRay.mkv"
|
||||
assert linked.is_file()
|
||||
assert linked.stat().st_ino == brut.stat().st_ino
|
||||
assert linked.read_text() == "donnees du mkv"
|
||||
# Rescan Radarr declenche.
|
||||
assert rescan_route.called
|
||||
# La fiche ne signale plus de lien casse.
|
||||
fiche = client.get(f"/api/files/{movie_id}").json()
|
||||
assert fiche["link_broken"] is False
|
||||
assert fiche["linked_mkv_path"] == str(linked)
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_repair_link_requires_brut_and_completed() -> None:
|
||||
"""La reparation exige un MKV brut present et un film traite."""
|
||||
reset_state()
|
||||
with SessionLocal() as db:
|
||||
db.add(
|
||||
IsoMovie(
|
||||
radarr_movie_id=10,
|
||||
radarr_movie_file_id=20,
|
||||
title="Film Sans Brut",
|
||||
year=2021,
|
||||
path=str(settings.radarr_films_dir / "Film Sans Brut (2021)" / "x.iso"),
|
||||
status="completed",
|
||||
last_seen_at=datetime(2026, 1, 1),
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
with TestClient(app) as client:
|
||||
movies = client.get("/api/movies").json()
|
||||
movie_id = movies[0]["id"]
|
||||
missing = client.post(f"/api/movies/{movie_id}/repair-link")
|
||||
assert missing.status_code == 409
|
||||
assert "MKV brut introuvable" in missing.json()["detail"]
|
||||
Reference in new issue
Block a user