Add queue override controls
Adds pause, stop, start, and cancel-current controls for #20.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
from importarr.config import Settings
|
||||
from importarr.state import State
|
||||
|
||||
|
||||
def configure_main(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("IMPORTARR_STATE_PATH", str(tmp_path / "initial.db"))
|
||||
import importarr.main as main
|
||||
|
||||
download = tmp_path / "downloads"
|
||||
movies = tmp_path / "movies"
|
||||
tv = tmp_path / "tv"
|
||||
monkeypatch.setattr(main, "settings", Settings(download_root=download, movies_root=movies, tv_root=tv, state_path=tmp_path / "state.db"))
|
||||
monkeypatch.setattr(main, "state", State(tmp_path / "state.db"))
|
||||
return main, download, movies, tv
|
||||
|
||||
|
||||
def test_pause_prevents_manual_queue_sync(tmp_path, monkeypatch):
|
||||
main, download, _movies, _tv = configure_main(tmp_path, monkeypatch)
|
||||
batch = download / "Release"
|
||||
batch.mkdir(parents=True)
|
||||
(batch / "Movie.mkv").write_bytes(b"movie")
|
||||
main.state.add_manual_batch(batch)
|
||||
|
||||
main.state.set_app_state("queue_mode", "paused")
|
||||
main.sync_manual_queue()
|
||||
|
||||
assert main.state.list_queue_items() == []
|
||||
|
||||
|
||||
def test_start_reenables_manual_queue_sync(tmp_path, monkeypatch):
|
||||
main, download, _movies, _tv = configure_main(tmp_path, monkeypatch)
|
||||
batch = download / "Release"
|
||||
batch.mkdir(parents=True)
|
||||
(batch / "Movie.mkv").write_bytes(b"movie")
|
||||
main.state.add_manual_batch(batch)
|
||||
|
||||
main.state.set_app_state("queue_mode", "paused")
|
||||
main.sync_manual_queue()
|
||||
main.state.set_app_state("queue_mode", "running")
|
||||
main.sync_manual_queue()
|
||||
|
||||
assert len(main.state.list_queue_items()) == 1
|
||||
|
||||
|
||||
def test_cancel_current_stops_before_next_manual_item(tmp_path, monkeypatch):
|
||||
main, download, movies, tv = configure_main(tmp_path, monkeypatch)
|
||||
batch = download / "Release"
|
||||
batch.mkdir(parents=True)
|
||||
(batch / "A.mkv").write_bytes(b"a")
|
||||
(batch / "B.mkv").write_bytes(b"b")
|
||||
main.state.add_manual_batch(batch)
|
||||
main.sync_manual_queue()
|
||||
main.state.set_app_state("cancel_requested", "true")
|
||||
|
||||
assert main._import_manual_batches(main.Importer(movies, tv)) == 0
|
||||
assert len(main.state.list_queue_items()) == 2
|
||||
|
||||
|
||||
def test_cancel_current_stops_active_copy(tmp_path, monkeypatch):
|
||||
main, download, movies, tv = configure_main(tmp_path, monkeypatch)
|
||||
batch = download / "Release"
|
||||
batch.mkdir(parents=True)
|
||||
source = batch / "A.mkv"
|
||||
source.write_bytes(b"a" * (1024 * 1024 + 1))
|
||||
main.state.add_manual_batch(batch)
|
||||
main.sync_manual_queue()
|
||||
|
||||
calls = 0
|
||||
|
||||
def cancel_during_copy() -> bool:
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
return calls > 1
|
||||
|
||||
monkeypatch.setattr(main, "consume_cancel_request", cancel_during_copy)
|
||||
|
||||
assert main._import_manual_batches(main.Importer(movies, tv)) == 0
|
||||
assert source.exists()
|
||||
assert not any(movies.glob("*.partial"))
|
||||
assert main.state.list_queue_items(active_only=False)[0]["state"] == "skipped"
|
||||
Reference in New Issue
Block a user