mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-26 19:05:13 +00:00
refactor(api): answer every API key question from one KeyPolicy
This commit is contained in:
@@ -14,6 +14,7 @@ import pytest
|
||||
import unshackle.core.cdm as cdm_mod
|
||||
from unshackle.commands.dl import dl
|
||||
from unshackle.core.api import handlers
|
||||
from unshackle.core.api.key_policy import KeyPolicy
|
||||
from unshackle.core.cdm.choice import choose_cdm, drm_system
|
||||
from unshackle.core.cdm.detect import is_playready_cdm
|
||||
|
||||
@@ -98,7 +99,8 @@ def answers(monkeypatch: pytest.MonkeyPatch, cdm: dict, profile: str | None, key
|
||||
"""What every ladder answers for one config row."""
|
||||
monkeypatch.setattr(handlers.config, "cdm", cdm, raising=False)
|
||||
user = {**TIER, **({"cdm": key_cdm} if key_cdm else {})}
|
||||
view = handlers.key_cdm_config(user)
|
||||
policy = KeyPolicy(user)
|
||||
view = policy.cdm_config()
|
||||
cmd = dl.__new__(dl)
|
||||
cmd.vaults = None
|
||||
track = SimpleNamespace(drm_preference=None)
|
||||
@@ -106,10 +108,10 @@ def answers(monkeypatch: pytest.MonkeyPatch, cdm: dict, profile: str | None, key
|
||||
"dl": each(LOCAL, lambda s: cmd.get_cdm("EXAMPLE", profile, drm=s)),
|
||||
"load": each(LOCAL, lambda s: handlers.load_full_cdm("EXAMPLE", profile, s, view)),
|
||||
"stub": each(LOCAL, lambda s: handlers.resolve_server_cdm("EXAMPLE", profile, s, view)),
|
||||
"device": each(SERVER, lambda s: handlers.resolve_device_name(user, s, "EXAMPLE")),
|
||||
"device": each(SERVER, lambda s: handlers.resolve_device_name(policy, s, "EXAMPLE")),
|
||||
"settled": attempt(lambda: handlers.detect_cdm_type_for_service("EXAMPLE", view)),
|
||||
"both": attempt(lambda: choose_cdm(view.cdm, "EXAMPLE").both),
|
||||
"candidates": each(SERVER, lambda s: handlers.server_drm_candidates("EXAMPLE", user, s, track)),
|
||||
"candidates": each(SERVER, lambda s: handlers.server_drm_candidates("EXAMPLE", policy, s, track)),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import zlib
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core.api import handlers
|
||||
from unshackle.core.api import handlers, key_policy
|
||||
from unshackle.core.api.errors import APIError
|
||||
from unshackle.core.api.handlers import load_client_cookies
|
||||
from unshackle.core.remote_protocol import APIErrorCode
|
||||
@@ -59,7 +59,7 @@ def built_ctx(monkeypatch):
|
||||
seen["ctx"] = parent_ctx
|
||||
return object()
|
||||
|
||||
monkeypatch.setattr(handlers, "load_service_config", lambda service: {})
|
||||
monkeypatch.setattr(key_policy, "load_service_config", lambda service: {})
|
||||
monkeypatch.setattr(handlers, "load_full_cdm", lambda *args: None)
|
||||
monkeypatch.setattr(handlers.Services, "load", lambda service: None)
|
||||
monkeypatch.setattr(handlers, "instantiate_service", fake_instantiate)
|
||||
|
||||
@@ -20,7 +20,7 @@ import pytest
|
||||
import unshackle.commands.dl as dl_module
|
||||
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
|
||||
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
|
||||
@@ -837,7 +837,7 @@ def test_a_remote_session_puts_the_flag_in_the_service_ctx(monkeypatch: pytest.M
|
||||
seen["ctx"] = parent_ctx
|
||||
return object()
|
||||
|
||||
monkeypatch.setattr(handlers, "load_service_config", lambda service: {})
|
||||
monkeypatch.setattr(key_policy, "load_service_config", lambda service: {})
|
||||
monkeypatch.setattr(handlers, "load_full_cdm", lambda *args: None)
|
||||
monkeypatch.setattr(handlers.Services, "load", lambda service: None)
|
||||
monkeypatch.setattr(handlers, "instantiate_service", fake_instantiate)
|
||||
|
||||
@@ -55,7 +55,7 @@ def cli_search(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> click.Context
|
||||
|
||||
def rest_handlers(monkeypatch: pytest.MonkeyPatch) -> tuple[Any, dict]:
|
||||
"""The handlers module with the service, its config, CDM and proxy stubbed, and the context it builds."""
|
||||
from unshackle.core.api import handlers
|
||||
from unshackle.core.api import handlers, key_policy
|
||||
|
||||
seen: dict = {}
|
||||
|
||||
@@ -63,7 +63,7 @@ def rest_handlers(monkeypatch: pytest.MonkeyPatch) -> tuple[Any, dict]:
|
||||
seen["ctx"] = parent_ctx
|
||||
return SimpleNamespace(authenticate=lambda cookies, credential: None)
|
||||
|
||||
monkeypatch.setattr(handlers, "load_service_config", lambda tag: {})
|
||||
monkeypatch.setattr(key_policy, "load_service_config", lambda tag: {})
|
||||
monkeypatch.setattr(handlers, "resolve_handler_proxy", lambda *a: (None, []))
|
||||
monkeypatch.setattr(handlers, "load_full_cdm", lambda *a: None)
|
||||
monkeypatch.setattr(handlers.Services, "load", lambda tag: SimpleNamespace())
|
||||
|
||||
Reference in New Issue
Block a user