Files
unshackle/tests/core/test_declared_kwargs.py
T
imSp4rky 0f9997be4c refactor(drm): drop the hardcoded service branch in the license flow
One service needed session_id in its license call, which a near-duplicate of get_content_keys supplied behind a service-tag test. service_licence now passes each service only the arguments its own license function declares, so the duplicate and the branch are gone. The REST API license paths and the base PlayReady delegate get the same filtering, replacing their fixed argument set.

Two behaviour changes ride along: an empty license challenge now raises EmptyLicense for every service, not just the one, and a service that declares only challenge now receives a working call instead of a TypeError.
2026-09-05 22:14:47 -06:00

35 lines
1.2 KiB
Python

from __future__ import annotations
from unshackle.core.utilities import declared_kwargs
SENT = {"challenge": b"c", "title": "t", "track": "tr", "pssh": "P", "session_id": "S"}
def test_keeps_only_declared_arguments() -> None:
def licence(*, challenge: bytes, title: str, track: str) -> None: ...
assert sorted(declared_kwargs(licence, SENT)) == ["challenge", "title", "track"]
def test_passes_session_id_to_a_function_that_asks_for_it() -> None:
def licence(*, challenge: bytes, title: str, track: str, session_id: str | None = None) -> None: ...
assert sorted(declared_kwargs(licence, SENT)) == ["challenge", "session_id", "title", "track"]
def test_a_var_keyword_function_gets_everything() -> None:
def licence(*, challenge: bytes, **kwargs: object) -> None: ...
assert declared_kwargs(licence, SENT) == SENT
def test_an_unreadable_signature_gets_everything() -> None:
# min() has no readable signature, and a compiled service may not either
assert declared_kwargs(min, SENT) == SENT
def test_a_signature_we_cannot_call_by_keyword_gets_everything() -> None:
def licence(challenge, /, **kwargs: object) -> None: ...
assert declared_kwargs(licence, SENT) == SENT