chore(verify): 预算版本管理UI修复验证脚本(API+浏览器双录,可复跑)

This commit is contained in:
Hermes CI Fix
2026-09-07 11:04:35 +08:00
parent b01a108874
commit f8018aa471
2 changed files with 273 additions and 0 deletions
@@ -0,0 +1,55 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""2026-09-07 预算版本管理UI修复 - 生产API验证"""
import json, urllib.request, ssl, sys
BASE = "https://cma.sxbh.ltd/api/cma"
def http(url, data=None, headers=None, method=None):
req = urllib.request.Request(url, data=data, headers=headers or {}, method=method)
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
with urllib.request.urlopen(req, timeout=30, context=ctx) as r:
return json.loads(r.read().decode())
def login(entity_id):
body = json.dumps({"username": "admin", "password": "admin123", "entity_id": entity_id}).encode()
r = http(BASE + "/auth/login", data=body, headers={"Content-Type": "application/json"}, method="POST")
return r["token"]
def versions(token, year=None):
url = BASE + "/budget/versions" + (f"?year={year}" if year else "")
r = http(url, headers={"Authorization": f"Bearer {token}"})
return r if isinstance(r, list) else r.get("data", r)
ok = True
for eid, ename in [(1, "酣客"), (2, "博海")]:
try:
tok = login(eid)
except Exception as e:
print(f"[{ename} entity{eid}] 登录失败: {e}")
ok = False
continue
try:
vs = versions(tok)
print(f"\n=== {ename} (entity={eid}) 共{len(vs)}个版本 ===")
for v in vs:
keys = sorted(v.keys())
print(f" {v['version']:>10} | status={v['status']:<10} | approval_status={v['approval_status']:<10} | plan_count={v['plan_count']} | kpi_count={v['kpi_count']} | total={v['total_budget']} | last_updated={v['last_updated']!r} | period_count={v['period_count']}")
# 断言新字段存在
for f in ["approval_status", "plan_count", "last_updated", "status", "kpi_count", "updated_at"]:
assert f in v, f"缺字段 {f}"
# 状态机映射断言
if v["status"] == "active":
assert v["approval_status"] == "draft", f"{v['version']} active 应映射 draft"
else:
assert v["approval_status"] == v["status"]
assert v["plan_count"] == v["kpi_count"]
assert v["last_updated"] == v["updated_at"]
except Exception as e:
print(f"[{ename}] 版本校验异常: {type(e).__name__} {e}")
ok = False
print("\n" + ("ALL_PASS" if ok else "HAS_FAIL"))
sys.exit(0 if ok else 1)