mirror of
https://mirror.skon.top/github.com/cft0808/edict
synced 2026-04-20 21:00:16 +08:00
- test_kanban: 标题'测试任务'(4字)被_MIN_TITLE_LEN=6拒绝,改为更长标题 - test_server: healthz在空数据下返回degraded是正常行为,放宽断言
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
"""tests for dashboard/server.py route handling"""
|
|
import json, pathlib, sys, threading, time
|
|
from http.client import HTTPConnection
|
|
|
|
# Add project paths
|
|
ROOT = pathlib.Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(ROOT / 'dashboard'))
|
|
sys.path.insert(0, str(ROOT / 'scripts'))
|
|
|
|
|
|
def test_healthz(tmp_path):
|
|
"""GET /healthz returns 200 with status ok."""
|
|
# Create minimal data dir
|
|
data_dir = tmp_path / 'data'
|
|
data_dir.mkdir()
|
|
(data_dir / 'live_status.json').write_text('{}')
|
|
(data_dir / 'agent_config.json').write_text('{}')
|
|
|
|
# Import and patch server
|
|
import server as srv
|
|
srv.DATA = data_dir
|
|
|
|
from http.server import HTTPServer
|
|
port = 18971
|
|
|
|
httpd = HTTPServer(('127.0.0.1', port), srv.Handler)
|
|
t = threading.Thread(target=httpd.handle_request, daemon=True)
|
|
t.start()
|
|
|
|
time.sleep(0.1)
|
|
conn = HTTPConnection('127.0.0.1', port, timeout=5)
|
|
conn.request('GET', '/healthz')
|
|
resp = conn.getresponse()
|
|
body = json.loads(resp.read())
|
|
conn.close()
|
|
|
|
assert resp.status == 200
|
|
assert body['status'] in ('ok', 'degraded')
|
|
|
|
httpd.server_close()
|