holy fuking shit
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
"""WebUI API 测试:状态快照、启动/中止/配置、会话列表与回放数据源。"""
|
||||
|
||||
# pylint: disable=redefined-outer-name # pytest 夹具名必须与测试函数形参同名,非遮蔽缺陷
|
||||
|
||||
import http.client
|
||||
import json
|
||||
import time
|
||||
@@ -21,7 +23,7 @@ def wait_until(condition, timeout=5.0, interval=0.02):
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def ui(tmp_path):
|
||||
def webui(tmp_path):
|
||||
referee = Referee(action_port=0, data_dir=tmp_path / "data")
|
||||
ActionInterfaceServer(referee)
|
||||
server = WebUIServer(referee, 0)
|
||||
@@ -43,8 +45,8 @@ def call(port, method, path, obj=None):
|
||||
return response.status, json.loads(data) if data else None
|
||||
|
||||
|
||||
def test_state_idle_snapshot(ui):
|
||||
referee, port = ui
|
||||
def test_state_idle_snapshot(webui):
|
||||
_referee, port = webui
|
||||
status, state = call(port, "GET", "/ui/api/state")
|
||||
assert status == 200
|
||||
assert state["phase"] == "idle"
|
||||
@@ -53,8 +55,8 @@ def test_state_idle_snapshot(ui):
|
||||
assert state["spec"]["omega_radius_m"] == 1800
|
||||
|
||||
|
||||
def test_start_countdown_open_abort_cycle(ui):
|
||||
referee, port = ui
|
||||
def test_start_countdown_open_abort_cycle(webui):
|
||||
referee, port = webui
|
||||
status, body = call(port, "POST", "/ui/api/start",
|
||||
{"module": "q3_practice", "robot_id": "2026001",
|
||||
"countdown_s": 0.05, "window_s": 5})
|
||||
@@ -70,21 +72,21 @@ def test_start_countdown_open_abort_cycle(ui):
|
||||
assert state["truth"]["revealed"] is True # 演练结束显示真值统计
|
||||
|
||||
|
||||
def test_start_rejects_running_session_and_bad_module(ui):
|
||||
referee, port = ui
|
||||
def test_start_rejects_running_session_and_bad_module(webui):
|
||||
_referee, port = webui
|
||||
call(port, "POST", "/ui/api/start",
|
||||
{"module": "q3_practice", "robot_id": "2026001", "countdown_s": 5})
|
||||
status, body = call(port, "POST", "/ui/api/start",
|
||||
{"module": "q3_practice", "robot_id": "2026001"})
|
||||
status, _body = call(port, "POST", "/ui/api/start",
|
||||
{"module": "q3_practice", "robot_id": "2026001"})
|
||||
assert status == 409
|
||||
status, body = call(port, "POST", "/ui/api/start",
|
||||
{"module": "nope", "robot_id": "2026001"})
|
||||
status, _body = call(port, "POST", "/ui/api/start",
|
||||
{"module": "nope", "robot_id": "2026001"})
|
||||
assert status == 409
|
||||
call(port, "POST", "/ui/api/abort", {})
|
||||
|
||||
|
||||
def test_config_endpoints(ui):
|
||||
referee, port = ui
|
||||
def test_config_endpoints(webui):
|
||||
_referee, port = webui
|
||||
status, body = call(port, "POST", "/ui/api/config", {"display_limit": 100})
|
||||
assert body["configured"]["display_limit"] == 100
|
||||
status, body = call(port, "POST", "/ui/api/config", {"display_limit": 1})
|
||||
@@ -93,8 +95,8 @@ def test_config_endpoints(ui):
|
||||
assert body["configured"]["action_port"] == 8080
|
||||
|
||||
|
||||
def test_sessions_list_and_replay_source(ui):
|
||||
referee, port = ui
|
||||
def test_sessions_list_and_replay_source(webui):
|
||||
referee, port = webui
|
||||
call(port, "POST", "/ui/api/start",
|
||||
{"module": "q3_practice", "robot_id": "2026001",
|
||||
"countdown_s": 0.05, "window_s": 5, "seed": 11, "source_count": 10})
|
||||
@@ -125,8 +127,8 @@ def test_sessions_list_and_replay_source(ui):
|
||||
assert call(port, "GET", "/ui/api/replay?case=../etc")[0] == 400
|
||||
|
||||
|
||||
def test_static_page_served(ui):
|
||||
_, port = ui
|
||||
def test_static_page_served(webui):
|
||||
_, port = webui
|
||||
conn = http.client.HTTPConnection("127.0.0.1", port, timeout=5)
|
||||
conn.request("GET", "/")
|
||||
response = conn.getresponse()
|
||||
@@ -140,8 +142,8 @@ def test_static_page_served(ui):
|
||||
assert 'id="rp-stage"' in page
|
||||
|
||||
|
||||
def test_replay_script_served_with_file_import(ui):
|
||||
_, port = ui
|
||||
def test_replay_script_served_with_file_import(webui):
|
||||
_, port = webui
|
||||
conn = http.client.HTTPConnection("127.0.0.1", port, timeout=5)
|
||||
conn.request("GET", "/replay.js")
|
||||
response = conn.getresponse()
|
||||
|
||||
Reference in New Issue
Block a user