🐛 Erreurs de fichiers explicites (droits, introuvable) sur chaque action + annulation reservee a l'etat a valider
This commit is contained in:
1 parent
70ce0b95a8
commit
6191b32bf7
4 files changed
+185
-35
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import errno
|
||||
import shutil
|
||||
import time
|
||||
from pathlib import Path
|
||||
@@ -351,3 +352,74 @@ def test_convert_blocked_by_workspace_leftovers() -> None:
|
||||
|
||||
def workspace_files_dir(folder: Path) -> list[str]:
|
||||
return sorted(entry.name for entry in folder.iterdir())
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_cancel_only_at_validating_and_tolerates_missing_files() -> None:
|
||||
"""L'annulation n'est possible qu'a l'etat "a valider". Un MKV deja
|
||||
disparu est tolere: l'annulation reste valable, retour a "detecte"."""
|
||||
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"]
|
||||
|
||||
# Hors "a valider": refus (le MKV converti n'existe pas avant).
|
||||
early = client.post(f"/api/movies/{movie_id}/cancel")
|
||||
assert early.status_code == 409
|
||||
|
||||
convert = client.post(f"/api/movies/{movie_id}/convert")
|
||||
assert convert.status_code == 200
|
||||
|
||||
# Apres conversion, on supprime physiquement le MKV et son lien
|
||||
# pour simuler des fichiers deja disparus.
|
||||
wait_for_status(client, "validating")
|
||||
folder = film_dir()
|
||||
for entry in folder.iterdir():
|
||||
if entry.suffix == ".mkv":
|
||||
entry.unlink()
|
||||
workspace = settings.downloads_dir / "ISO Movie 2025"
|
||||
if workspace.is_dir():
|
||||
shutil.rmtree(workspace)
|
||||
|
||||
cancel = client.post(f"/api/movies/{movie_id}/cancel")
|
||||
assert cancel.status_code == 200
|
||||
assert cancel.json()["status"] == "detected"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_cancel_reports_permission_error(monkeypatch) -> None:
|
||||
"""Une erreur de droits pendant l'annulation remonte un message
|
||||
explicite (via notification) et le film reste "a valider"."""
|
||||
reset_state()
|
||||
create_film_folder()
|
||||
mock_radarr(str(settings.radarr_films_dir / FILM_FOLDER))
|
||||
import app.converter as converter_module
|
||||
|
||||
def refuse_unlink(path: Path) -> None:
|
||||
# Comme le vrai unlink_if_exists: l'OSError est traduite en message
|
||||
# explicite avant de remonter.
|
||||
raise converter_module.file_error(
|
||||
PermissionError(errno.EACCES, "Permission denied", str(path)),
|
||||
"Suppression",
|
||||
path,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(converter_module, "unlink_if_exists", refuse_unlink)
|
||||
with TestClient(app) as client:
|
||||
configure_radarr(client)
|
||||
client.post("/api/scans")
|
||||
movie_id = client.get("/api/movies").json()[0]["id"]
|
||||
convert = client.post(f"/api/movies/{movie_id}/convert")
|
||||
assert convert.status_code == 200
|
||||
wait_for_status(client, "validating")
|
||||
|
||||
cancel = client.post(f"/api/movies/{movie_id}/cancel")
|
||||
assert cancel.status_code == 409
|
||||
assert "erreur de droits" in cancel.json()["detail"]
|
||||
assert "Annulation impossible" in cancel.json()["detail"]
|
||||
|
||||
movie = client.get("/api/movies").json()[0]
|
||||
assert movie["status"] == "validating"
|
||||
Reference in new issue
Block a user