refactor(api): admit download job create and retry through one job_admission step

This commit is contained in:
imSp4rky
2026-11-25 23:15:16 -07:00
parent 92e8abbdbc
commit ee8e968127
27 changed files with 584 additions and 417 deletions
+5 -4
View File
@@ -14,9 +14,10 @@ from pyplayready.system.pssh import PSSH as PR_PSSH
from pywidevine.cdm import Cdm as WidevineCdm
from pywidevine.pssh import PSSH
from tests.admission import refusal
from tests.core.key_resolver import NoVaults, key_table, resolver
from unshackle.commands.dl import dl
from unshackle.core.api.handlers import load_full_cdm, resolve_server_cdm, validate_download_parameters
from unshackle.core.api.handlers import load_full_cdm, resolve_server_cdm
from unshackle.core.cdm.detect import is_widevine_cdm
from unshackle.core.drm import PlayReady, Widevine
from unshackle.core.manifests import HLS
@@ -208,9 +209,9 @@ def test_the_other_drm_system_can_return_a_different_set_of_kids() -> None:
def test_the_api_refuses_all_drm_with_one_device() -> None:
assert "cdm" in (validate_download_parameters({"all_drm": True, "cdm": "device"}) or "")
assert validate_download_parameters({"all_drm": True, "cdm_only": True}) is None
assert validate_download_parameters({"all_drm": True, "cdm_only": False}) is None
assert "cdm" in (refusal({"all_drm": True, "cdm": "device"}) or "")
assert refusal({"all_drm": True, "cdm_only": True}) is None
assert refusal({"all_drm": True, "cdm_only": False}) is None
def test_a_content_key_in_a_vault_stops_the_challenge_of_each_drm_system() -> None:
+3 -3
View File
@@ -18,10 +18,10 @@ from typing import Any
import pytest
import unshackle.commands.dl as dl_module
from tests.admission import refusal
from tests.remote.unit.test_remote_service_helpers import _sent_create_data
from unshackle.core import mux_step
from unshackle.core.api import download_manager, handlers, key_policy
from unshackle.core.api.handlers import validate_download_parameters
from unshackle.core.config import config
from unshackle.core.mux_step import hybrid_plan, hybrid_source_tracks, hybrid_step_error, missing_hybrid_error
from unshackle.core.service import Service, TrackRequest
@@ -784,8 +784,8 @@ def test_the_hybrid_step_gets_the_base_alone_when_there_is_no_dv(tmp_path: Path)
def test_the_api_takes_generate_dv_with_any_range_as_dl_does(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("unshackle.core.binaries.DoviTool", Path("dovi_tool"))
for data in ({}, {"range": ["SDR"]}, {"range": ["DV"]}, {"range": ["HYBRID"]}, {"range": ["HDR10"]}):
assert validate_download_parameters({"generate_dv": True, **data}) is None
assert "boolean" in (validate_download_parameters({"generate_dv": "yes", "range": ["HYBRID"]}) or "")
assert refusal({"generate_dv": True, **data}) is None
assert "boolean" in (refusal({"generate_dv": "yes", "range": ["HYBRID"]}) or "")
class _Captured(Exception):
+3 -3
View File
@@ -4,8 +4,8 @@ from __future__ import annotations
import pytest
from tests.admission import refusal
from unshackle.commands.dl import latest_episode_keys
from unshackle.core.api.handlers import validate_download_parameters
from unshackle.core.titles import Movie, Movies, Series
from unshackle.core.titles.episode import Episode
@@ -52,8 +52,8 @@ def test_titles_that_are_not_a_series_are_left_alone() -> None:
@pytest.mark.parametrize("value", [0, -1, True, "3", 1.5])
def test_a_non_positive_or_non_integer_count_is_refused(value: object) -> None:
assert validate_download_parameters({"latest_episodes": value}) == "latest_episodes must be a positive integer"
assert refusal({"latest_episodes": value}) == "latest_episodes must be a positive integer"
def test_a_positive_count_is_accepted() -> None:
assert validate_download_parameters({"latest_episodes": 3}) is None
assert refusal({"latest_episodes": 3}) is None
+11 -13
View File
@@ -4,7 +4,7 @@ from __future__ import annotations
import pytest
from unshackle.core.api.handlers import validate_download_parameters
from tests.admission import refusal
from unshackle.core.config import config
from unshackle.core.run_plan import PlanError, validate_metadata_ids
@@ -90,18 +90,18 @@ def test_one_kind_keeping_the_provider_is_enough(monkeypatch: pytest.MonkeyPatch
],
)
def test_api_refuses_two_ids(payload: dict) -> None:
err = validate_download_parameters(payload)
err = refusal(payload)
assert err and "cannot be used together" in err
@pytest.mark.parametrize("payload", [{"tmdb_id": 27205}, {"imdb_id": "tt1375666"}, {"tvdb_id": 73871}, {}])
def test_api_accepts_one_id(payload: dict, monkeypatch: pytest.MonkeyPatch) -> None:
with_keys(monkeypatch, tmdb_api_key="k", tvdb_api_key="k")
assert validate_download_parameters(payload) is None
assert refusal(payload) is None
def test_api_still_reports_a_malformed_id_first() -> None:
err = validate_download_parameters({"tmdb_id": "12345", "imdb_id": "tt1"})
err = refusal({"tmdb_id": "12345", "imdb_id": "tt1"})
assert err and "positive integer" in err
@@ -133,21 +133,21 @@ def test_a_malformed_anilist_value_is_refused(monkeypatch: pytest.MonkeyPatch, v
@pytest.mark.parametrize("payload", [{"anilist_id": 21}, {"anilist_id": "mal:21"}, {"anilist_id": "21"}])
def test_api_accepts_an_anilist_id(payload: dict) -> None:
assert validate_download_parameters(payload) is None
assert refusal(payload) is None
def test_api_accepts_anilist_alongside_one_western_id() -> None:
assert validate_download_parameters({"imdb_id": "tt1375666", "anilist_id": 21}) is None
assert refusal({"imdb_id": "tt1375666", "anilist_id": 21}) is None
def test_api_still_refuses_two_western_ids_with_anilist() -> None:
err = validate_download_parameters({"tmdb_id": 27205, "imdb_id": "tt1375666", "anilist_id": 21})
err = refusal({"tmdb_id": 27205, "imdb_id": "tt1375666", "anilist_id": 21})
assert err and "cannot be used together" in err
@pytest.mark.parametrize("value", [0, -3, True, "mal:", "tt1375666", "anilist:21", 1.5])
def test_api_refuses_a_malformed_anilist_id(value: object) -> None:
err = validate_download_parameters({"anilist_id": value})
err = refusal({"anilist_id": value})
assert err and "anilist" in err
@@ -162,17 +162,15 @@ def test_a_non_positive_or_non_decimal_anilist_value_is_refused(monkeypatch: pyt
@pytest.mark.parametrize("payload", [{"anilist_id": "MAL:21"}, {"anilist_id": "007"}, {"anilist_id": " 21 "}])
def test_api_accepts_what_the_cli_accepts(payload: dict) -> None:
"""Both surfaces share parse_anilist_ref, so their accept sets cannot drift."""
assert validate_download_parameters(payload) is None
assert refusal(payload) is None
@pytest.mark.parametrize("value", ["0", "mal:0", "²"])
def test_api_refuses_what_the_cli_refuses(value: str) -> None:
err = validate_download_parameters({"anilist_id": value})
err = refusal({"anilist_id": value})
assert err and "anilist" in err
def test_api_refuses_an_id_no_configured_provider_can_find(monkeypatch: pytest.MonkeyPatch) -> None:
with_keys(monkeypatch)
assert validate_download_parameters({"tmdb_id": 27205}) == (
"--tmdb needs the tmdb provider: set tmdb_api_key in your config"
)
assert refusal({"tmdb_id": 27205}) == "--tmdb needs the tmdb provider: set tmdb_api_key in your config"