forked from kenzuya/unshackle
refactor(api): build list, search and session services through one launch_served
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
|
||||
import base64
|
||||
import zlib
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.remote.sessions import launch_session
|
||||
from unshackle.core.api import handlers, key_policy
|
||||
from unshackle.core.api.errors import APIError
|
||||
from unshackle.core.api.handlers import load_client_cookies
|
||||
@@ -52,12 +54,12 @@ def test_load_client_cookies_rejects_a_malformed_blob(blob):
|
||||
|
||||
@pytest.fixture
|
||||
def built_ctx(monkeypatch):
|
||||
"""Stub the service machinery so create_service_instance runs without a real service; return the captured ctx."""
|
||||
"""Stub the service machinery so a session launch runs without a real service; return the captured ctx."""
|
||||
seen = {}
|
||||
|
||||
def fake_instantiate(parent_ctx, *args):
|
||||
seen["ctx"] = parent_ctx
|
||||
return object()
|
||||
return SimpleNamespace()
|
||||
|
||||
monkeypatch.setattr(key_policy, "load_service_config", lambda service: {})
|
||||
monkeypatch.setattr(handlers, "load_full_cdm", lambda *args: None)
|
||||
@@ -65,7 +67,7 @@ def built_ctx(monkeypatch):
|
||||
monkeypatch.setattr(handlers, "instantiate_service", fake_instantiate)
|
||||
|
||||
def build(data):
|
||||
_, cookies, _ = handlers.create_service_instance("EXAMPLE", "title", data, None, [], None)
|
||||
cookies = launch_session("EXAMPLE", "title", data).cookies
|
||||
return seen["ctx"], cookies
|
||||
|
||||
return build
|
||||
|
||||
@@ -19,6 +19,7 @@ import pytest
|
||||
|
||||
import unshackle.commands.dl as dl_module
|
||||
from tests.admission import refusal
|
||||
from tests.remote.sessions import launch_session
|
||||
from tests.remote.unit.test_remote_service_helpers import _sent_create_data
|
||||
from unshackle.core import mux_step
|
||||
from unshackle.core.api import download_manager, handlers, key_policy
|
||||
@@ -835,7 +836,7 @@ def test_a_remote_session_puts_the_flag_in_the_service_ctx(monkeypatch: pytest.M
|
||||
|
||||
def fake_instantiate(parent_ctx: Any, *args: Any) -> object:
|
||||
seen["ctx"] = parent_ctx
|
||||
return object()
|
||||
return SimpleNamespace()
|
||||
|
||||
monkeypatch.setattr(key_policy, "load_service_config", lambda service: {})
|
||||
monkeypatch.setattr(handlers, "load_full_cdm", lambda *args: None)
|
||||
@@ -843,7 +844,7 @@ def test_a_remote_session_puts_the_flag_in_the_service_ctx(monkeypatch: pytest.M
|
||||
monkeypatch.setattr(handlers, "instantiate_service", fake_instantiate)
|
||||
data = {"generate_dv": True} if to_dv else {}
|
||||
|
||||
handlers.create_service_instance("EXAMPLE", "title", data, None, [], None)
|
||||
launch_session("EXAMPLE", "title", data)
|
||||
|
||||
assert seen["ctx"].params["generate_dv"] is to_dv
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from typing import Any
|
||||
import click
|
||||
import pytest
|
||||
|
||||
from tests.remote.sessions import launch_session
|
||||
from unshackle.core.launch import LaunchKeys
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
@@ -81,7 +82,7 @@ def rest_relay(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> click.Context
|
||||
|
||||
def rest_list(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> click.Context:
|
||||
handlers, seen = rest_handlers(monkeypatch)
|
||||
handlers.setup_list_service({}, "EXAMPLE", None, "t")
|
||||
handlers.launch_served(handlers.LIST, {}, "EXAMPLE", "t", None)
|
||||
return seen["ctx"]
|
||||
|
||||
|
||||
@@ -101,7 +102,7 @@ def rest_search(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> click.Contex
|
||||
|
||||
def rest_session(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> click.Context:
|
||||
handlers, seen = rest_handlers(monkeypatch)
|
||||
handlers.create_service_instance("EXAMPLE", "t", {}, None, [], None)
|
||||
launch_session("EXAMPLE", "t", {})
|
||||
return seen["ctx"]
|
||||
|
||||
|
||||
@@ -167,11 +168,9 @@ def served_paths(monkeypatch: pytest.MonkeyPatch) -> dict[str, Callable[[dict],
|
||||
|
||||
return {
|
||||
"relay": lambda data: handlers.relay_service(data, "server", None, "t").parent,
|
||||
"list": lambda data: captured(lambda: handlers.setup_list_service(data, "EXAMPLE", None, "t")),
|
||||
"list": lambda data: captured(lambda: handlers.launch_served(handlers.LIST, data, "EXAMPLE", "t", None)),
|
||||
"search": lambda data: captured(lambda: handlers.run_service_search(data, "EXAMPLE", "query")),
|
||||
"session": lambda data: captured(
|
||||
lambda: handlers.create_service_instance("EXAMPLE", "t", data, None, [], None)
|
||||
),
|
||||
"session": lambda data: captured(lambda: launch_session("EXAMPLE", "t", data)),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user