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 -5
View File
@@ -10,9 +10,9 @@ from typing import Any
import pytest
from tests.admission import refusal
from tests.lang_selection import test_kind_only_selection as harness
from unshackle.commands.dl import dl
from unshackle.core.api.handlers import validate_download_parameters
from unshackle.core.utilities import kind_only_conflict
KEYS = ["audio_description_only", "forced_subs_only"]
@@ -56,18 +56,18 @@ def test_kind_only_conflict(params, expected):
def test_api_rejects_a_conflict():
assert validate_download_parameters({**BASE, "audio_description_only": True, "no_audio": True}) == (
assert refusal({**BASE, "audio_description_only": True, "no_audio": True}) == (
"--audio-description-only cannot be used with --no-audio: --no-audio drops the tracks that "
"--audio-description-only selects."
)
assert validate_download_parameters({**BASE, "audio_description_only": True, "audio_only": True}) is None
assert refusal({**BASE, "audio_description_only": True, "audio_only": True}) is None
@pytest.mark.parametrize("key", [*KEYS, "audio_description", "audio_only"])
def test_api_rejects_a_non_boolean_flag(key):
# the string "false" is truthy in dl.result, so it would turn the flag on
assert validate_download_parameters({**BASE, key: "false"}) == f"{key} must be a boolean"
assert validate_download_parameters({**BASE, key: None}) is None
assert refusal({**BASE, key: "false"}) == f"{key} must be a boolean"
assert refusal({**BASE, key: None}) is None
@pytest.mark.parametrize("flags", [{"forced_subs_only": True}, {"forced_s_lang": ["en"]}, {"forced_s_lang": ["-en"]}])
+6 -11
View File
@@ -93,11 +93,11 @@ def test_api_passes_the_flags_through(key):
def test_api_accepts_the_require_flags():
from unshackle.core.api.handlers import validate_download_parameters
from tests.admission import refusal
# unlike require_subs, these carry no conflict with a language selection
assert (
validate_download_parameters(
refusal(
{"service": "EXAMPLE", "title": "x", "require_audio": ["en"], "require_video": ["en"], "lang": ["en", "fr"]}
)
is None
@@ -121,22 +121,17 @@ def test_api_reaches_dl_result(key, default):
@pytest.mark.parametrize("key", ["require_audio", "require_video"])
def test_api_rejects_a_non_array_require_value(key, value):
# a JSON string iterates character by character and blows up in langcodes, so it must 400 first
from unshackle.core.api.handlers import validate_download_parameters
from tests.admission import refusal
error = validate_download_parameters({"service": "EXAMPLE", "title": "x", key: value})
error = refusal({"service": "EXAMPLE", "title": "x", key: value})
assert error == f"{key} must be an array of language strings"
def test_require_subs_no_longer_conflicts_with_s_lang():
# gate and selection are separate concerns: -sl decides what to keep, --require-subs only gates
from unshackle.core.api.handlers import validate_download_parameters
from tests.admission import refusal
assert (
validate_download_parameters(
{"service": "EXAMPLE", "title": "x", "s_lang": ["en", "ko", "ja"], "require_subs": ["en"]}
)
is None
)
assert refusal({"service": "EXAMPLE", "title": "x", "s_lang": ["en", "ko", "ja"], "require_subs": ["en"]}) is None
def test_exact_lang_turns_off_the_bare_tag_fallback():