forked from kenzuya/unshackle
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -4,18 +4,13 @@ from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import functools
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from unshackle.core import remote_channel, remote_lifetime
|
||||
from unshackle.core import remote_protocol as protocol
|
||||
from unshackle.core import remote_service
|
||||
from unshackle.core.api import routes
|
||||
from unshackle.core.api.handlers import SESSION_TRANSPORT_KEYS
|
||||
|
||||
ROUTE_NAMES = {name for name in vars(protocol) if name.endswith("_ROUTE")}
|
||||
CLIENT_METHODS = {
|
||||
@@ -75,20 +70,6 @@ def client_calls() -> tuple[set[tuple[str, str]], set[str]]:
|
||||
return calls, referenced
|
||||
|
||||
|
||||
def test_the_client_writes_no_api_path_of_its_own():
|
||||
"""A path the client writes out by hand escapes the route check below."""
|
||||
tree = client_tree()
|
||||
docstrings = {id(node.value) for node in ast.walk(tree) if isinstance(node, ast.Expr)}
|
||||
assert not [
|
||||
node.lineno
|
||||
for node in ast.walk(tree)
|
||||
if isinstance(node, ast.Constant)
|
||||
and isinstance(node.value, str)
|
||||
and "/api/" in node.value
|
||||
and id(node) not in docstrings
|
||||
]
|
||||
|
||||
|
||||
def test_every_route_the_client_calls_is_served_with_that_method():
|
||||
calls, referenced = client_calls()
|
||||
assert calls, "the scan found no client calls"
|
||||
@@ -103,22 +84,6 @@ def test_the_server_takes_its_remote_session_routes_from_the_protocol():
|
||||
assert {path for path in served_paths if path.startswith("/api/session")} <= protocol_paths
|
||||
|
||||
|
||||
def test_the_protocol_page_lists_each_remote_route():
|
||||
"""The route table of the protocol page holds the routes that a remote-only server mounts, and no other.
|
||||
|
||||
Each route of the table that the page itself documents has a section of its own.
|
||||
"""
|
||||
page = (ROOT / "docs" / "dev" / "rest-api" / "remote-sessions.md").read_text(encoding="utf-8")
|
||||
listed = set(re.findall(r"^\| `(GET|POST|DELETE)` \| `([^`]+)` \|", page, re.MULTILINE))
|
||||
sections = set(re.findall(r"^### `(GET|POST|DELETE) ([^`]+)`$", page, re.MULTILINE))
|
||||
assert listed == {(method, path) for method, path, _, remote in routes.ROUTES if remote}
|
||||
assert sections == listed - {
|
||||
("GET", protocol.HEALTH_ROUTE),
|
||||
("GET", protocol.SERVICES_ROUTE),
|
||||
("POST", protocol.SEARCH_ROUTE),
|
||||
}
|
||||
|
||||
|
||||
def test_the_wire_values_stay_pinned():
|
||||
"""Both halves read one record, so only this list catches a renamed value on the wire."""
|
||||
assert {name: getattr(protocol, name) for name in ROUTE_NAMES} == {
|
||||
@@ -156,61 +121,6 @@ def test_the_wire_values_stay_pinned():
|
||||
]
|
||||
|
||||
|
||||
def test_session_transport_keys_are_the_create_body():
|
||||
"""The server keeps these out of the flat service options; it reads them from the session create body."""
|
||||
assert SESSION_TRANSPORT_KEYS == {
|
||||
"service",
|
||||
"title_id",
|
||||
"session_id",
|
||||
"profile",
|
||||
"service_params",
|
||||
"season",
|
||||
"episode",
|
||||
"part",
|
||||
"wanted",
|
||||
"proxy",
|
||||
"no_proxy",
|
||||
"credentials",
|
||||
"cookies",
|
||||
"cache",
|
||||
"client_region",
|
||||
"proxy_region",
|
||||
"server_cdm",
|
||||
"cdm_type",
|
||||
"cdm_security_level",
|
||||
"cdm_system_id",
|
||||
"cdm_device_type",
|
||||
"service_config",
|
||||
"range_",
|
||||
"vcodec",
|
||||
"quality",
|
||||
"best_available",
|
||||
"generate_dv",
|
||||
"dl_params",
|
||||
"plugins",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"shape,fields",
|
||||
[
|
||||
(protocol.ChannelPrompt, {"type", "id", "prompt", "qr"}),
|
||||
(protocol.ChannelCdmCall, {"type", "id", "call"}),
|
||||
(protocol.ChannelLog, {"type", "seq", "level", "message", "ts", "qr"}),
|
||||
(protocol.ChannelStatus, {"type", "status", "error"}),
|
||||
(protocol.ChannelDrain, {"type", "draining"}),
|
||||
(protocol.ChannelAnswer, {"type", "id", "response", "error"}),
|
||||
],
|
||||
)
|
||||
def test_the_channel_messages_keep_their_fields(shape, fields):
|
||||
"""A session channel message is a JSON text frame; the other side reads these keys."""
|
||||
assert keys(shape) == fields
|
||||
|
||||
|
||||
def test_a_client_error_kind_is_never_a_server_error_code():
|
||||
assert not {k.value for k in protocol.ClientErrorKind} & {c.value for c in protocol.APIErrorCode}
|
||||
|
||||
|
||||
def keys(shape: Any) -> set[str]:
|
||||
return set(shape.__required_keys__ | shape.__optional_keys__)
|
||||
|
||||
@@ -219,24 +129,3 @@ def properties(schema: dict | None) -> set[str]:
|
||||
return set(
|
||||
((schema or {}).get("content", {}).get("application/json", {}).get("schema", {}) or {}).get("properties", {})
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"method,route,request_shape,reply_shape",
|
||||
[
|
||||
("POST", protocol.SESSION_CREATE_ROUTE, protocol.SessionCreate, protocol.SessionCreated),
|
||||
("POST", protocol.TRACKS_ROUTE, protocol.TracksRequest, None),
|
||||
("POST", protocol.SEGMENT_FILTER_ROUTE, protocol.SegmentFilterRequest, protocol.SegmentFilterReply),
|
||||
("POST", protocol.LICENSE_ROUTE, protocol.LicenseRequest, protocol.LicenseReply),
|
||||
("POST", protocol.KEYS_ROUTE, protocol.TrackKeys, None),
|
||||
("POST", protocol.BAD_KEY_ROUTE, protocol.BadKeyReport, None),
|
||||
("GET", protocol.SESSION_ROUTE, None, protocol.SessionInfo),
|
||||
],
|
||||
)
|
||||
def test_the_openapi_yaml_names_only_protocol_keys(method, route, request_shape, reply_shape):
|
||||
"""The Swagger docs of a route list a subset of the keys its protocol shapes declare."""
|
||||
spec = yaml.safe_load((SERVED[(method, route)].__doc__ or "").split("---", 1)[1])
|
||||
if request_shape:
|
||||
assert properties(spec.get("requestBody")) <= keys(request_shape)
|
||||
if reply_shape:
|
||||
assert properties(spec["responses"].get("200")) <= keys(reply_shape)
|
||||
|
||||
Reference in New Issue
Block a user