-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_runtime_ui_slice05.py
More file actions
79 lines (64 loc) · 2.8 KB
/
test_runtime_ui_slice05.py
File metadata and controls
79 lines (64 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from __future__ import annotations
import http.client
import json
from pathlib import Path
import urllib.parse
from Implementations.Reference.Runtime.python.runtime_core import find_repo_root
from Implementations.Reference.Runtime.python.ui_runtime import build_runtime
def _repo_root() -> Path:
return find_repo_root(Path(__file__).resolve())
def _load_acceptance() -> dict:
path = _repo_root() / "Implementations" / "Reference" / "Runtime" / "acceptance" / "example05_runtime_family.acceptance.json"
return json.loads(path.read_text(encoding="utf-8"))
def _resolve_repo_path(relative_path: str) -> Path:
return _repo_root() / relative_path
def test_slice05_ui_routes_and_state_match_shared_acceptance() -> None:
acceptance = _load_acceptance()
contract_path = _resolve_repo_path(acceptance["artifact_refs"]["contract_path"])
wfrog_path = _resolve_repo_path(acceptance["artifact_refs"]["wfrog_path"])
snapshot_path = _resolve_repo_path(acceptance["artifact_refs"]["snapshot_path"])
expected_snapshot = json.loads(snapshot_path.read_text(encoding="utf-8"))
runtime = build_runtime(
contract_path=contract_path,
wfrog_path=wfrog_path,
host="127.0.0.1",
port=0,
open_browser=False,
)
httpd, thread = runtime.serve_in_thread()
try:
host, port = httpd.server_address
connection = http.client.HTTPConnection(host, port, timeout=5)
connection.request("GET", "/")
response = connection.getresponse()
html = response.read().decode("utf-8")
assert response.status == 200
for route in acceptance["ui"]["expected_routes"]:
if route in {"/", "/run"}:
continue
assert route in html
for asset_route in ("/asset/numeric_control_svg", "/asset/numeric_indicator_svg"):
connection.request("GET", asset_route)
asset_response = connection.getresponse()
asset_body = asset_response.read().decode("utf-8")
assert asset_response.status == 200
assert "<svg" in asset_body
body = urllib.parse.urlencode({"input_value": str(acceptance["headless"]["input_value"])})
connection.request(
"POST",
"/run",
body=body,
headers={"Content-Type": "application/x-www-form-urlencoded"},
)
post_response = connection.getresponse()
post_response.read()
assert post_response.status == 303
connection.request("GET", "/state.json")
state_response = connection.getresponse()
state = json.loads(state_response.read().decode("utf-8"))
assert state_response.status == 200
assert state == expected_snapshot
finally:
httpd.shutdown()
thread.join(timeout=2)
httpd.server_close()