piphi-runtime-testkit-python 0.1.4__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- piphi_runtime_testkit_python/__init__.py +21 -1
- piphi_runtime_testkit_python/assertions.py +36 -0
- piphi_runtime_testkit_python/camera.py +150 -0
- {piphi_runtime_testkit_python-0.1.4.dist-info → piphi_runtime_testkit_python-0.2.0.dist-info}/METADATA +1 -1
- piphi_runtime_testkit_python-0.2.0.dist-info/RECORD +12 -0
- piphi_runtime_testkit_python-0.1.4.dist-info/RECORD +0 -11
- {piphi_runtime_testkit_python-0.1.4.dist-info → piphi_runtime_testkit_python-0.2.0.dist-info}/WHEEL +0 -0
- {piphi_runtime_testkit_python-0.1.4.dist-info → piphi_runtime_testkit_python-0.2.0.dist-info}/entry_points.txt +0 -0
- {piphi_runtime_testkit_python-0.1.4.dist-info → piphi_runtime_testkit_python-0.2.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
"""Pytest-first helpers for testing PiPhi runtime integrations."""
|
|
2
2
|
|
|
3
|
-
from .assertions import
|
|
3
|
+
from .assertions import (
|
|
4
|
+
assert_entities_response,
|
|
5
|
+
assert_event_sent,
|
|
6
|
+
assert_state_refresh_response,
|
|
7
|
+
assert_telemetry_sent,
|
|
8
|
+
)
|
|
4
9
|
from .builders import (
|
|
5
10
|
build_config_payload,
|
|
6
11
|
build_config_snapshot,
|
|
7
12
|
build_core_config_row,
|
|
8
13
|
build_runtime_headers,
|
|
9
14
|
)
|
|
15
|
+
from .camera import (
|
|
16
|
+
CAMERA_MEDIA_CONTRACT_VERSION,
|
|
17
|
+
assert_camera_capability,
|
|
18
|
+
assert_public_camera_message_redacted,
|
|
19
|
+
build_camera_session_offer,
|
|
20
|
+
build_camera_sidecar_session_open,
|
|
21
|
+
build_camera_source,
|
|
22
|
+
)
|
|
10
23
|
from .behavior_contract import (
|
|
11
24
|
BehaviorTelemetryIssue,
|
|
12
25
|
assert_behavior_conditions_match_telemetry,
|
|
@@ -17,12 +30,19 @@ from .mock_core import CapturedRequest, MockCoreServer, RUNTIME_CONFIG_FETCH_PAT
|
|
|
17
30
|
__all__ = [
|
|
18
31
|
"CapturedRequest",
|
|
19
32
|
"BehaviorTelemetryIssue",
|
|
33
|
+
"CAMERA_MEDIA_CONTRACT_VERSION",
|
|
20
34
|
"MockCoreServer",
|
|
21
35
|
"RUNTIME_CONFIG_FETCH_PATH",
|
|
22
36
|
"assert_entities_response",
|
|
37
|
+
"assert_camera_capability",
|
|
23
38
|
"assert_behavior_conditions_match_telemetry",
|
|
24
39
|
"assert_event_sent",
|
|
40
|
+
"assert_state_refresh_response",
|
|
25
41
|
"assert_telemetry_sent",
|
|
42
|
+
"assert_public_camera_message_redacted",
|
|
43
|
+
"build_camera_session_offer",
|
|
44
|
+
"build_camera_sidecar_session_open",
|
|
45
|
+
"build_camera_source",
|
|
26
46
|
"build_config_payload",
|
|
27
47
|
"build_config_snapshot",
|
|
28
48
|
"build_core_config_row",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from datetime import datetime
|
|
3
4
|
from typing import Any
|
|
4
5
|
|
|
5
6
|
from .mock_core import CapturedRequest, MockCoreServer
|
|
@@ -166,3 +167,38 @@ def assert_entities_response(payload: Any) -> dict[str, Any]:
|
|
|
166
167
|
raise AssertionError(f"Expected /entities payload commands to be an object, but received {commands!r}.")
|
|
167
168
|
|
|
168
169
|
return payload
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def assert_state_refresh_response(
|
|
173
|
+
payload: Any,
|
|
174
|
+
*,
|
|
175
|
+
request_id: str,
|
|
176
|
+
) -> dict[str, Any]:
|
|
177
|
+
"""Assert that ``/state?refresh=true`` proves an upstream state read."""
|
|
178
|
+
|
|
179
|
+
if not isinstance(payload, dict):
|
|
180
|
+
raise AssertionError(
|
|
181
|
+
f"Expected refreshed /state payload to be an object, but received {payload!r}."
|
|
182
|
+
)
|
|
183
|
+
receipt = payload.get("refresh")
|
|
184
|
+
if not isinstance(receipt, dict):
|
|
185
|
+
raise AssertionError("Expected refreshed /state payload to include a refresh receipt.")
|
|
186
|
+
if receipt.get("request_id") != request_id:
|
|
187
|
+
raise AssertionError("Expected refresh receipt to echo the current refresh request id.")
|
|
188
|
+
if receipt.get("performed") is not True or receipt.get("status") != "refreshed":
|
|
189
|
+
raise AssertionError("Expected refresh receipt to confirm an upstream read.")
|
|
190
|
+
source = receipt.get("source")
|
|
191
|
+
if not isinstance(source, str) or not source.strip():
|
|
192
|
+
raise AssertionError("Expected refresh receipt to name its upstream source.")
|
|
193
|
+
observed_at = receipt.get("observed_at")
|
|
194
|
+
try:
|
|
195
|
+
parsed = datetime.fromisoformat(str(observed_at).replace("Z", "+00:00"))
|
|
196
|
+
except ValueError as exc:
|
|
197
|
+
raise AssertionError(
|
|
198
|
+
"Expected refresh receipt to include a valid observation timestamp."
|
|
199
|
+
) from exc
|
|
200
|
+
if parsed.tzinfo is None:
|
|
201
|
+
raise AssertionError(
|
|
202
|
+
"Expected refresh observation timestamp to include a timezone."
|
|
203
|
+
)
|
|
204
|
+
return payload
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""Camera-media v1 builders and conformance assertions."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
from urllib.parse import urlsplit
|
|
7
|
+
|
|
8
|
+
CAMERA_MEDIA_CONTRACT_VERSION = "camera.media.v1"
|
|
9
|
+
PUBLIC_CAMERA_AUDIENCES = {"browser-core"}
|
|
10
|
+
CAMERA_SECRET_FIELDS = {
|
|
11
|
+
"authorization",
|
|
12
|
+
"password",
|
|
13
|
+
"source_url",
|
|
14
|
+
"token",
|
|
15
|
+
"username",
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def build_camera_source(
|
|
20
|
+
*,
|
|
21
|
+
camera_id: str = "camera-1",
|
|
22
|
+
source_url: str = "rtsp://camera.local/live",
|
|
23
|
+
preferred_transport: str = "tcp",
|
|
24
|
+
connect_timeout_seconds: int = 10,
|
|
25
|
+
) -> dict[str, Any]:
|
|
26
|
+
"""Build an internal camera source descriptor for runtime/sidecar tests."""
|
|
27
|
+
|
|
28
|
+
parsed = urlsplit(source_url)
|
|
29
|
+
return {
|
|
30
|
+
"contract_version": CAMERA_MEDIA_CONTRACT_VERSION,
|
|
31
|
+
"message_type": "camera.source",
|
|
32
|
+
"audience": "core-sidecar",
|
|
33
|
+
"camera_id": camera_id,
|
|
34
|
+
"source_url": source_url,
|
|
35
|
+
"source_protocol": parsed.scheme.lower(),
|
|
36
|
+
"preferred_transport": preferred_transport,
|
|
37
|
+
"connect_timeout_seconds": connect_timeout_seconds,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def build_camera_session_offer(
|
|
42
|
+
*,
|
|
43
|
+
sdp: str = "v=0\r\na=recvonly\r\n",
|
|
44
|
+
include_audio: bool = False,
|
|
45
|
+
) -> dict[str, Any]:
|
|
46
|
+
"""Build a browser-to-Core WebRTC offer."""
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
"contract_version": CAMERA_MEDIA_CONTRACT_VERSION,
|
|
50
|
+
"message_type": "camera.session.offer",
|
|
51
|
+
"audience": "browser-core",
|
|
52
|
+
"type": "offer",
|
|
53
|
+
"sdp": sdp,
|
|
54
|
+
"include_audio": include_audio,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def build_camera_sidecar_session_open(
|
|
59
|
+
*,
|
|
60
|
+
source: dict[str, Any] | None = None,
|
|
61
|
+
offer: dict[str, Any] | None = None,
|
|
62
|
+
idle_timeout_seconds: int = 60,
|
|
63
|
+
) -> dict[str, Any]:
|
|
64
|
+
"""Build the private Core-to-sidecar session request."""
|
|
65
|
+
|
|
66
|
+
browser_offer = offer or build_camera_session_offer()
|
|
67
|
+
return {
|
|
68
|
+
"contract_version": CAMERA_MEDIA_CONTRACT_VERSION,
|
|
69
|
+
"message_type": "camera.sidecar.session.open",
|
|
70
|
+
"audience": "core-sidecar",
|
|
71
|
+
"source": source or build_camera_source(),
|
|
72
|
+
"offer": {
|
|
73
|
+
"type": browser_offer["type"],
|
|
74
|
+
"sdp": browser_offer["sdp"],
|
|
75
|
+
"include_audio": bool(browser_offer.get("include_audio", False)),
|
|
76
|
+
},
|
|
77
|
+
"idle_timeout_seconds": idle_timeout_seconds,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _field_names(value: object) -> set[str]:
|
|
82
|
+
if isinstance(value, dict):
|
|
83
|
+
names = {str(key).lower() for key in value}
|
|
84
|
+
for nested in value.values():
|
|
85
|
+
names.update(_field_names(nested))
|
|
86
|
+
return names
|
|
87
|
+
if isinstance(value, list):
|
|
88
|
+
names: set[str] = set()
|
|
89
|
+
for nested in value:
|
|
90
|
+
names.update(_field_names(nested))
|
|
91
|
+
return names
|
|
92
|
+
return set()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def assert_public_camera_message_redacted(payload: Any) -> dict[str, Any]:
|
|
96
|
+
"""Assert that a browser-facing camera message contains no source secrets."""
|
|
97
|
+
|
|
98
|
+
if not isinstance(payload, dict):
|
|
99
|
+
raise AssertionError( # noqa: TRY004 - assertion helper intentionally raises AssertionError
|
|
100
|
+
f"Expected camera message object, received {payload!r}."
|
|
101
|
+
)
|
|
102
|
+
if payload.get("contract_version") != CAMERA_MEDIA_CONTRACT_VERSION:
|
|
103
|
+
raise AssertionError("Expected camera.media.v1 contract_version.")
|
|
104
|
+
if payload.get("audience") not in PUBLIC_CAMERA_AUDIENCES:
|
|
105
|
+
raise AssertionError("Expected a browser-facing camera message.")
|
|
106
|
+
leaked = _field_names(payload) & CAMERA_SECRET_FIELDS
|
|
107
|
+
if leaked:
|
|
108
|
+
raise AssertionError(f"Browser-facing camera message leaked secret fields: {sorted(leaked)!r}.")
|
|
109
|
+
return payload
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def assert_camera_capability(
|
|
113
|
+
entities_payload: Any,
|
|
114
|
+
*,
|
|
115
|
+
capability_id: str = "camera_stream",
|
|
116
|
+
) -> dict[str, Any]:
|
|
117
|
+
"""Assert that an entities response advertises a usable camera capability."""
|
|
118
|
+
|
|
119
|
+
if not isinstance(entities_payload, dict):
|
|
120
|
+
raise AssertionError( # noqa: TRY004 - assertion helper intentionally raises AssertionError
|
|
121
|
+
"Expected /entities payload to be an object."
|
|
122
|
+
)
|
|
123
|
+
capabilities = entities_payload.get("capabilities")
|
|
124
|
+
if not isinstance(capabilities, dict):
|
|
125
|
+
raise AssertionError( # noqa: TRY004 - assertion helper intentionally raises AssertionError
|
|
126
|
+
"Expected /entities capabilities to be an object."
|
|
127
|
+
)
|
|
128
|
+
capability = capabilities.get(capability_id)
|
|
129
|
+
if not isinstance(capability, dict) or capability.get("kind") != "camera":
|
|
130
|
+
raise AssertionError(f"Expected {capability_id!r} to be a camera capability.")
|
|
131
|
+
camera = capability.get("camera")
|
|
132
|
+
if not isinstance(camera, dict):
|
|
133
|
+
raise AssertionError( # noqa: TRY004 - assertion helper intentionally raises AssertionError
|
|
134
|
+
f"Expected {capability_id!r} to declare camera media endpoints."
|
|
135
|
+
)
|
|
136
|
+
endpoint_names = {
|
|
137
|
+
"gateway_source_endpoint",
|
|
138
|
+
"snapshot_endpoint",
|
|
139
|
+
"stream_endpoint",
|
|
140
|
+
"webrtc_endpoint",
|
|
141
|
+
}
|
|
142
|
+
if not endpoint_names.intersection(camera):
|
|
143
|
+
raise AssertionError(f"Expected {capability_id!r} to declare at least one media endpoint.")
|
|
144
|
+
entities = entities_payload.get("entities")
|
|
145
|
+
if not isinstance(entities, list) or not any(
|
|
146
|
+
isinstance(entity, dict) and capability_id in (entity.get("capabilities") or [])
|
|
147
|
+
for entity in entities
|
|
148
|
+
):
|
|
149
|
+
raise AssertionError(f"Expected an entity to advertise {capability_id!r}.")
|
|
150
|
+
return capability
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
piphi_runtime_testkit_python-0.2.0.dist-info/METADATA,sha256=Ss_NWIfquq6r3mOzO5F423vOApI-3N18MLtlu71iScY,26281
|
|
2
|
+
piphi_runtime_testkit_python-0.2.0.dist-info/WHEEL,sha256=IuIk3wbaEnFH1cx75iM2R1CmliRI3dFLXTbRakgvgFQ,90
|
|
3
|
+
piphi_runtime_testkit_python-0.2.0.dist-info/entry_points.txt,sha256=zTIXoQOJK3VVIMOfKpB5Y3vnSbyFgyU45GZCb7fLGHI,120
|
|
4
|
+
piphi_runtime_testkit_python-0.2.0.dist-info/licenses/LICENSE,sha256=pS6szQI4X7qAin1ODdoDp-XwZvsFy6ZZ28-JAwGHgzo,1070
|
|
5
|
+
piphi_runtime_testkit_python/__init__.py,sha256=cJoXuYy9a1oZhMFwswZZ4No1Px0WbH6fY2tTrIu28OY,1466
|
|
6
|
+
piphi_runtime_testkit_python/assertions.py,sha256=UI_82X52fOyJqvlj-0uruPZOoMCADA7V993cw4_cIWM,8613
|
|
7
|
+
piphi_runtime_testkit_python/behavior_contract.py,sha256=ENLodK3wpt_zxJn4AFBCgw-zhfT4du93SFQZyh194oE,9054
|
|
8
|
+
piphi_runtime_testkit_python/builders.py,sha256=UmxPB1fSDGqhQzcpmmzBH4w3ZSGxtWHXQ4bfZL18kd0,2961
|
|
9
|
+
piphi_runtime_testkit_python/camera.py,sha256=h0bKfAOuD9s8gWtVM7ONcolu_euX120DjrSH0i4p1bA,5356
|
|
10
|
+
piphi_runtime_testkit_python/mock_core.py,sha256=IG37ZwnrrXiVVIhApvwTRAo1uAy2FbICBpRdb6etnDc,7533
|
|
11
|
+
piphi_runtime_testkit_python/pytest_plugin.py,sha256=8LUxO-2o7PZOQeMLQ2THbtfwn2HJ91vXkwGiYipmNuw,965
|
|
12
|
+
piphi_runtime_testkit_python-0.2.0.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
piphi_runtime_testkit_python-0.1.4.dist-info/METADATA,sha256=scck6ownxllmcSJjiiqUVvCBpJEazHwsxXwRVtzRlbU,26281
|
|
2
|
-
piphi_runtime_testkit_python-0.1.4.dist-info/WHEEL,sha256=IuIk3wbaEnFH1cx75iM2R1CmliRI3dFLXTbRakgvgFQ,90
|
|
3
|
-
piphi_runtime_testkit_python-0.1.4.dist-info/entry_points.txt,sha256=zTIXoQOJK3VVIMOfKpB5Y3vnSbyFgyU45GZCb7fLGHI,120
|
|
4
|
-
piphi_runtime_testkit_python-0.1.4.dist-info/licenses/LICENSE,sha256=pS6szQI4X7qAin1ODdoDp-XwZvsFy6ZZ28-JAwGHgzo,1070
|
|
5
|
-
piphi_runtime_testkit_python/__init__.py,sha256=oXliAmDgzDNPTvIqfmjqoALQ1ZEXr32NLavy7K4Oeao,933
|
|
6
|
-
piphi_runtime_testkit_python/assertions.py,sha256=uxekhD6uha5S00KAE42G_IlVbuG5AaZpErF5rKQwNLk,7105
|
|
7
|
-
piphi_runtime_testkit_python/behavior_contract.py,sha256=ENLodK3wpt_zxJn4AFBCgw-zhfT4du93SFQZyh194oE,9054
|
|
8
|
-
piphi_runtime_testkit_python/builders.py,sha256=UmxPB1fSDGqhQzcpmmzBH4w3ZSGxtWHXQ4bfZL18kd0,2961
|
|
9
|
-
piphi_runtime_testkit_python/mock_core.py,sha256=IG37ZwnrrXiVVIhApvwTRAo1uAy2FbICBpRdb6etnDc,7533
|
|
10
|
-
piphi_runtime_testkit_python/pytest_plugin.py,sha256=8LUxO-2o7PZOQeMLQ2THbtfwn2HJ91vXkwGiYipmNuw,965
|
|
11
|
-
piphi_runtime_testkit_python-0.1.4.dist-info/RECORD,,
|
{piphi_runtime_testkit_python-0.1.4.dist-info → piphi_runtime_testkit_python-0.2.0.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|