Files
unshackle/tests/remote/sessions.py
T

62 lines
2.3 KiB
Python

"""A real remote session entry for the tests that call the session and licence handlers directly."""
from collections.abc import Callable
from types import SimpleNamespace
from typing import Any
import pytest
from unshackle.core.api import handlers, key_policy
from unshackle.core.api.handlers import Launched, SessionLaunch
from unshackle.core.api.input_bridge import InputBridge
from unshackle.core.api.key_policy import KeyPolicy
from unshackle.core.api.session_store import SessionEntry
from unshackle.core.remote_protocol import LicensingMode, Licensor
def session_entry(**fields: Any) -> SessionEntry:
"""A remote session that the server CDM licenses, unless *fields* set another :class:`SessionEntry` value."""
return SessionEntry(
**{
"session_id": "sess",
"service_tag": "EXAMPLE",
"service_instance": SimpleNamespace(),
"licensing": LicensingMode(Licensor.SERVER_CDM),
**fields,
}
)
def session_launch(licensor: Licensor = Licensor.NO_DEVICE, **fields: Any) -> SessionLaunch:
"""The session purpose of ``launch_served``: no device and no server account, unless *fields* set another value."""
return SessionLaunch(
**{
"proxy": (None, []),
"policy": KeyPolicy.of(None),
"server_account": False,
"licensing": LicensingMode(licensor),
"input_bridge": InputBridge(),
"cache_dir": "_sessions/test/EXAMPLE",
**fields,
}
)
def launch_session(
service: str,
title: str,
data: dict,
profile: str | None = None,
licensor: Licensor = Licensor.NO_DEVICE,
**fields: Any,
) -> Launched:
"""``launch_served`` for a remote session of *service* with the :func:`session_launch` purpose."""
return handlers.launch_served(session_launch(licensor, **fields), data, service, title, profile)
def stub_service_build(monkeypatch: pytest.MonkeyPatch, build: Callable[[], Any]) -> None:
"""Make every served launch build its service with *build*, with no service config or CDM behind it."""
monkeypatch.setattr(key_policy, "load_service_config", lambda tag: {})
monkeypatch.setattr(handlers, "load_full_cdm", lambda *a: None)
monkeypatch.setattr(handlers, "instantiate_service", lambda *a, **k: build())