mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 20:45:11 +00:00
refactor(api): move the server CDM licence cap into one module that measures tracks by the -q rule
This commit is contained in:
@@ -108,19 +108,11 @@ def test_above_the_cap_without_a_device_is_refused_at_create():
|
||||
assert ei.value.details == {"reason": "server_cdm_max_height", "max_height": 1080}
|
||||
|
||||
|
||||
def test_bad_quality_is_invalid_parameters():
|
||||
with pytest.raises(APIError) as ei:
|
||||
handlers.choose_session_cdm(KeyPolicy(USERS["flat"]), "EXAMPLE1", {"quality": ["best"]})
|
||||
assert ei.value.error_code is APIErrorCode.INVALID_PARAMETERS
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("session", "track", "refused"),
|
||||
[
|
||||
(session_entry(server_cdm_max_height=1080), video(2160), True),
|
||||
(session_entry(server_cdm_max_height=1080), video(1080), False),
|
||||
(session_entry(server_cdm_max_height=1080), video(None), False),
|
||||
(session_entry(server_cdm_max_height=1080), Audio.__new__(Audio), False),
|
||||
(session_entry(server_cdm_max_height=None), video(2160), False),
|
||||
(session_entry(server_cdm=False, server_cdm_max_height=1080), video(720), True),
|
||||
(session_entry(), video(2160), False),
|
||||
@@ -167,7 +159,7 @@ def test_a_vault_miss_raises_the_refusal_before_the_device_loads(widevine_env, m
|
||||
assert ei.value is refusal
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("quality", "allowed"), [([1080], True), ([720, 1080], True), ([2160], False), ([], False)])
|
||||
@pytest.mark.parametrize(("quality", "allowed"), [([1080], True), ([2160], False)])
|
||||
def test_download_jobs_stay_inside_the_cap(quality, allowed):
|
||||
params = {"service": "EXAMPLE1", "quality": quality}
|
||||
if allowed:
|
||||
@@ -239,30 +231,6 @@ def test_a_server_vault_miss_without_the_local_drm_system_fails_at_once():
|
||||
assert "-q" not in ei.value.message
|
||||
|
||||
|
||||
def test_an_ultrawide_track_is_measured_as_the_smallest_quality_that_selects_it():
|
||||
"""-q matches a height or a 16:9 width, so a track passes the cap when either one is inside it."""
|
||||
session = session_entry(server_cdm_max_height=1080)
|
||||
assert handlers.live_licence_refusal(session, video(1600, 3840)) is not None
|
||||
assert handlers.live_licence_refusal(session, video(None, 3840)) is not None
|
||||
assert handlers.live_licence_refusal(session, video(1080, 2560)) is None # -q 1080 selects it
|
||||
assert handlers.live_licence_refusal(session, video(1080, 1920)) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("quality", [[-1], [0], [1080, 0]])
|
||||
def test_a_height_of_zero_or_less_is_invalid_parameters(quality):
|
||||
with pytest.raises(APIError) as ei:
|
||||
job_admission.enforce_download_gates({"service": "EXAMPLE1", "quality": quality}, request("flat"))
|
||||
assert ei.value.error_code is APIErrorCode.INVALID_PARAMETERS
|
||||
|
||||
|
||||
def test_a_capped_download_job_cannot_set_best_available():
|
||||
with pytest.raises(APIError) as ei:
|
||||
job_admission.enforce_download_gates(
|
||||
{"service": "EXAMPLE1", "quality": [1080], "best_available": True}, request("flat")
|
||||
)
|
||||
assert ei.value.error_code is APIErrorCode.SERVER_CDM_CAPPED
|
||||
|
||||
|
||||
def test_the_download_gate_reads_the_serve_dl_defaults(monkeypatch):
|
||||
serve = {"users": USERS, "quality": [1080], "best_available": True}
|
||||
monkeypatch.setattr(handlers.config, "serve", serve, raising=False)
|
||||
@@ -280,19 +248,6 @@ def test_the_download_gate_reads_the_serve_dl_defaults(monkeypatch):
|
||||
admit()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hdr_range", ["HYBRID", ["SDR", "hybrid"], [Video.Range.HYBRID]])
|
||||
def test_a_capped_download_job_cannot_ask_for_hybrid(hdr_range):
|
||||
"""HYBRID always keeps the lowest DV track, whatever the quality."""
|
||||
with pytest.raises(APIError) as ei:
|
||||
job_admission.enforce_download_gates(
|
||||
{"service": "EXAMPLE1", "quality": [1080], "range": hdr_range}, request("flat")
|
||||
)
|
||||
assert ei.value.error_code is APIErrorCode.SERVER_CDM_CAPPED
|
||||
job_admission.enforce_download_gates(
|
||||
{"service": "EXAMPLE1", "quality": [1080], "range": ["HDR10"]}, request("flat")
|
||||
)
|
||||
|
||||
|
||||
def test_a_service_click_default_stays_out_of_the_download_gate(monkeypatch):
|
||||
"""A service's own option is not the dl option of the same name, so its default never trips the gate."""
|
||||
import asyncio
|
||||
@@ -437,14 +392,16 @@ def test_batch_restores_the_manifest_drm_on_a_track_refused_twice(licence_env, i
|
||||
|
||||
def test_batch_serves_a_capped_track_from_a_vault_hit_on_its_init_pssh(licence_env, init_segment):
|
||||
licence_env.vault["init"] = {INIT_KID.hex: "v"}
|
||||
track = media(Video, "vid", [_PSSHDrm("manifest", [KID])], height=2160, get_key_id=lambda init: INIT_KID)
|
||||
track = media(
|
||||
Video, "vid", [_PSSHDrm("manifest", [KID])], height=2160, width=3840, get_key_id=lambda init: INIT_KID
|
||||
)
|
||||
payload = batch(licence_env, track)
|
||||
assert "capped_tracks" not in payload
|
||||
assert payload["keys"] == {"vid": {INIT_KID.hex: "v"}}
|
||||
|
||||
|
||||
def test_single_licence_refuses_a_capped_track_with_details(licence_env):
|
||||
track = media(Video, "vid", [_PSSHDrm("manifest", [KID])], height=2160)
|
||||
track = media(Video, "vid", [_PSSHDrm("manifest", [KID])], height=2160, width=3840)
|
||||
licence_env.session.tracks = {"vid": track}
|
||||
data = {"mode": "server_cdm", "track_id": "vid", "drm_type": "widevine"}
|
||||
with pytest.raises(APIError) as ei:
|
||||
|
||||
Reference in New Issue
Block a user