Signed-off-by: 南通一次元科技有限公司 <guwangtu@icimeta.com>
This commit is contained in:
commit
b91954df4a
106 files changed
+43359
No files matched your search
+137
@@ -0,0 +1,137 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""审计管理平台冒烟测试。
|
||||
|
||||
用法:
|
||||
python deploy/冒烟测试.py
|
||||
python deploy/冒烟测试.py --url http://your-server:8080 --user shenji --password '***'
|
||||
|
||||
检查:登录(可选)、核心页面、核心接口、静态资源。返回码 0 表示全部通过。
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
except Exception:
|
||||
pass
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import http.cookiejar
|
||||
|
||||
|
||||
PAGES = [
|
||||
("统一入口", "/"),
|
||||
("数字化审计", "/digital-audit"),
|
||||
("知识库", "/knowledge"),
|
||||
("系统设置", "/settings"),
|
||||
("旧门户", "/portal"),
|
||||
]
|
||||
|
||||
APIS = [
|
||||
("健康检查", "/api/health"),
|
||||
("当前用户", "/api/me"),
|
||||
("平台状态", "/api/platform/status"),
|
||||
("驾驶舱", "/api/da/overview"),
|
||||
("待办中心", "/api/da/todo"),
|
||||
("规则库", "/api/da/rules"),
|
||||
("审计任务", "/api/da/tasks"),
|
||||
("整改统计", "/api/da/rectifications/stats"),
|
||||
("整改报表", "/api/da/rectifications/report?dimension=dept"),
|
||||
("整改组织分布", "/api/da/rectifications/map"),
|
||||
("OCR 任务", "/api/da/ocr/tasks"),
|
||||
("要素抽取任务", "/api/da/extract/tasks"),
|
||||
("审计作业统计", "/api/da/workflow/stats"),
|
||||
("解析记录", "/api/da/parsed"),
|
||||
("数据资源", "/api/da/datasources"),
|
||||
("分析模型", "/api/da/models"),
|
||||
]
|
||||
|
||||
STATIC = [
|
||||
("数字化审计 core.js", "/static/js/core.js"),
|
||||
("数字化审计 boot.js", "/static/js/boot.js"),
|
||||
("数字化审计 CSS", "/static/digital_audit.css"),
|
||||
]
|
||||
|
||||
|
||||
def build_opener():
|
||||
cj = http.cookiejar.CookieJar()
|
||||
return urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
||||
|
||||
|
||||
def login(opener, base, user, password):
|
||||
data = urllib.parse.urlencode({"username": user, "password": password, "next": "/"}).encode()
|
||||
req = urllib.request.Request(base + "/api/login", data=data, method="POST")
|
||||
try:
|
||||
resp = opener.open(req, timeout=15)
|
||||
return resp.status in (200, 303)
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code in (200, 303)
|
||||
|
||||
|
||||
def check(opener, url, expect_json=False):
|
||||
try:
|
||||
resp = opener.open(urllib.request.Request(url), timeout=20)
|
||||
body = resp.read()
|
||||
if resp.status != 200:
|
||||
return False, f"HTTP {resp.status}"
|
||||
if expect_json:
|
||||
try:
|
||||
json.loads(body.decode("utf-8"))
|
||||
except Exception:
|
||||
return False, "返回不是合法 JSON"
|
||||
return True, f"200 / {len(body)} bytes"
|
||||
except urllib.error.HTTPError as e:
|
||||
return False, f"HTTP {e.code}"
|
||||
except Exception as e:
|
||||
return False, str(e)[:80]
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--url", default="http://127.0.0.1:8080")
|
||||
parser.add_argument("--user", default="")
|
||||
parser.add_argument("--password", default="")
|
||||
args = parser.parse_args()
|
||||
base = args.url.rstrip("/")
|
||||
opener = build_opener()
|
||||
failures = []
|
||||
|
||||
if args.user:
|
||||
ok = login(opener, base, args.user, args.password)
|
||||
print(("[OK]" if ok else "[FAIL]") + " 登录")
|
||||
if not ok:
|
||||
failures.append("登录")
|
||||
|
||||
print("\n== 页面 ==")
|
||||
for name, path in PAGES:
|
||||
ok, detail = check(opener, base + path)
|
||||
print(("[OK]" if ok else "[FAIL]") + f" {name}: {detail}")
|
||||
if not ok:
|
||||
failures.append(name)
|
||||
|
||||
print("\n== 接口 ==")
|
||||
for name, path in APIS:
|
||||
ok, detail = check(opener, base + path, expect_json=True)
|
||||
print(("[OK]" if ok else "[FAIL]") + f" {name}: {detail}")
|
||||
if not ok:
|
||||
failures.append(name)
|
||||
|
||||
print("\n== 静态资源 ==")
|
||||
for name, path in STATIC:
|
||||
ok, detail = check(opener, base + path)
|
||||
print(("[OK]" if ok else "[FAIL]") + f" {name}: {detail}")
|
||||
if not ok:
|
||||
failures.append(name)
|
||||
|
||||
print("\n" + "=" * 40)
|
||||
if failures:
|
||||
print(f"冒烟测试失败 {len(failures)} 项:{'、'.join(failures)}")
|
||||
return 1
|
||||
print("冒烟测试全部通过")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user