forked from kenzuya/unshackle
refactor(export): move the --export writer out of dl into core ExportWriter
This commit is contained in:
@@ -2,35 +2,34 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
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(written: list[tuple[Any, ...]]) -> dl:
|
||||
def runner() -> dl:
|
||||
cmd = dl.__new__(dl)
|
||||
cmd.vaults = SimpleNamespace()
|
||||
cmd.service = "EXAMPLE"
|
||||
cmd.debug_logger = None
|
||||
cmd._remote_service = SimpleNamespace()
|
||||
cmd.write_export = lambda *args: written.append(args) # type: ignore[method-assign]
|
||||
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, tmp_path: Path, cdm_only: bool, vaults_only: bool, best_available: bool
|
||||
monkeypatch: pytest.MonkeyPatch, cdm_only: bool, vaults_only: bool, best_available: bool
|
||||
) -> None:
|
||||
monkeypatch.setattr(verify, "DECRYPT_HOOK", None)
|
||||
written: list[tuple[Any, ...]] = []
|
||||
cmd = runner(written)
|
||||
writer = create_autospec(ExportWriter, instance=True)
|
||||
cmd = runner()
|
||||
service = SimpleNamespace()
|
||||
|
||||
cmd.start_key_resolution(
|
||||
@@ -38,7 +37,7 @@ def test_the_resolver_takes_the_run_flags_and_becomes_the_decrypt_hook(
|
||||
cdm_only=cdm_only,
|
||||
vaults_only=vaults_only,
|
||||
best_available=best_available,
|
||||
export=tmp_path / "export.json",
|
||||
export=writer,
|
||||
)
|
||||
|
||||
keys = cmd.keys
|
||||
@@ -48,12 +47,12 @@ def test_the_resolver_takes_the_run_flags_and_becomes_the_decrypt_hook(
|
||||
assert keys.vaults is cmd.vaults and keys.tag == "EXAMPLE"
|
||||
assert keys.export is not None
|
||||
keys.export("title", "track", "drm")
|
||||
assert written == [(tmp_path / "export.json", "title", "track", "drm")]
|
||||
writer.record.assert_called_once_with("title", "track", "drm")
|
||||
|
||||
|
||||
def test_no_export_path_gives_no_export_callback(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_no_export_gives_no_export_callback(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(verify, "DECRYPT_HOOK", None)
|
||||
cmd = runner([])
|
||||
cmd = runner()
|
||||
|
||||
cmd.start_key_resolution(SimpleNamespace(), cdm_only=False, vaults_only=True, best_available=False, export=None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user