Files
unshackle/tests/commands/test_key_resolution_wiring.py
T

60 lines
2.0 KiB
Python

"""dl builds its content-key resolution from the run's flags and installs the verified decrypt as the hook."""
from __future__ import annotations
from types import SimpleNamespace
from unittest.mock import create_autospec
import pytest
from unshackle.commands.dl import dl
from unshackle.core.drm import verify
from unshackle.core.export_writer import ExportWriter
pytestmark = pytest.mark.unit
def runner() -> dl:
cmd = dl.__new__(dl)
cmd.vaults = SimpleNamespace()
cmd.service = "EXAMPLE"
cmd.debug_logger = None
cmd._remote_service = SimpleNamespace()
return cmd
@pytest.mark.parametrize("cdm_only, vaults_only, best_available", [(True, False, False), (False, True, True)])
def test_the_resolver_takes_the_run_flags_and_becomes_the_decrypt_hook(
monkeypatch: pytest.MonkeyPatch, cdm_only: bool, vaults_only: bool, best_available: bool
) -> None:
monkeypatch.setattr(verify, "DECRYPT_HOOK", None)
writer = create_autospec(ExportWriter, instance=True)
cmd = runner()
service = SimpleNamespace()
cmd.start_key_resolution(
service,
cdm_only=cdm_only,
vaults_only=vaults_only,
best_available=best_available,
export=writer,
)
keys = cmd.keys
assert verify.DECRYPT_HOOK == cmd.keys.decrypt_verified
assert (keys.cdm_only, keys.vaults_only, keys.best_available) == (cdm_only, vaults_only, best_available)
assert keys.source is cmd._remote_service and keys.service is service and keys.cdms is cmd
assert keys.vaults is cmd.vaults and keys.tag == "EXAMPLE"
assert keys.export is not None
keys.export("title", "track", "drm")
writer.record.assert_called_once_with("title", "track", "drm")
def test_no_export_gives_no_export_callback(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(verify, "DECRYPT_HOOK", None)
cmd = runner()
cmd.start_key_resolution(SimpleNamespace(), cdm_only=False, vaults_only=True, best_available=False, export=None)
assert cmd.keys.export is None