Add API update controls #22
This commit is contained in:
@@ -131,3 +131,43 @@ def test_cancel_current_stops_active_copy(tmp_path, monkeypatch):
|
||||
assert source.exists()
|
||||
assert not any(movies.glob("*.partial"))
|
||||
assert main.state.list_queue_items(active_only=False)[0]["state"] == "skipped"
|
||||
|
||||
|
||||
def test_control_update_runs_configured_command(tmp_path, monkeypatch):
|
||||
main, _download, _movies, _tv = configure_main(tmp_path, monkeypatch)
|
||||
main.settings.update_command = ["upgrade", "now"]
|
||||
|
||||
calls = []
|
||||
|
||||
def fake_run(command, **kwargs):
|
||||
calls.append((command, kwargs))
|
||||
return main.subprocess.CompletedProcess(command, 0, stdout="updated", stderr="")
|
||||
|
||||
monkeypatch.setattr(main.subprocess, "run", fake_run)
|
||||
|
||||
result = main.update_service()
|
||||
|
||||
assert result["status"] == "ok"
|
||||
assert result["command"] == ["upgrade", "now"]
|
||||
assert result["stdout"] == "updated"
|
||||
assert calls[0][0] == ["upgrade", "now"]
|
||||
assert calls[0][1].get("shell") is not True
|
||||
|
||||
|
||||
def test_control_restart_reports_command_failure(tmp_path, monkeypatch):
|
||||
main, _download, _movies, _tv = configure_main(tmp_path, monkeypatch)
|
||||
main.settings.restart_command = ["restart"]
|
||||
|
||||
def fake_run(command, **kwargs):
|
||||
return main.subprocess.CompletedProcess(command, 1, stdout="", stderr="failed")
|
||||
|
||||
monkeypatch.setattr(main.subprocess, "run", fake_run)
|
||||
|
||||
try:
|
||||
main.restart_service()
|
||||
except main.HTTPException as exc:
|
||||
assert exc.status_code == 500
|
||||
assert exc.detail["status"] == "failed"
|
||||
assert exc.detail["stderr"] == "failed"
|
||||
else:
|
||||
raise AssertionError("expected HTTPException")
|
||||
|
||||
Reference in New Issue
Block a user