Files
kra-new/scripts/sw_activation_http_smoke.py
T

43 lines
2.0 KiB
Python

"""查询运行实例的渠道激活接口,仅执行只读请求。"""
import argparse
import json
import urllib.parse
import urllib.request
from pathlib import Path
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--base-url", default="http://127.0.0.1:18000")
parser.add_argument("--token-file", required=True, type=Path)
parser.add_argument("--output", required=True, type=Path)
args = parser.parse_args()
token = args.token_file.read_text(encoding="utf-8").strip()
checks = []
paths = [
("/sw/promoteActivePool/bindList?pageNum=1&pageSize=10", 0),
("/sw/promoteActivePool/bindList?platformNames=lx,hw&statuses=reached", 0),
("/sw/promoteActivePool/bindList?" + urllib.parse.urlencode({"statuses": "已达标", "busierAccount": "does-not-exist"}), 0),
("/sw/promoteActivePool/bindSpendDetail?id=0", 7),
]
for path, expected in paths:
request = urllib.request.Request(args.base_url + path, headers={"x-token": token})
with urllib.request.urlopen(request, timeout=30) as response:
body = json.load(response)
item = {"method": "GET", "path": path, "http": response.status, "code": body.get("code"),
"msg": body.get("msg"), "passed": response.status == 200 and body.get("code") == expected}
if isinstance(body.get("data"), dict) and "rows" in body["data"]:
item.update(total=body["data"]["total"], available=body["data"].get("available"))
checks.append(item)
print(json.dumps(item, ensure_ascii=False))
report = {"scope": "当前 sw7 运行实例,只读请求;OA 未接入场景明确返回 available=false。完整 OA 与流水数据通过两个隔离数据库的 TCP HTTP 测试。",
"checks": checks, "passed": all(item["passed"] for item in checks)}
args.output.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
if not report["passed"]:
raise SystemExit(1)
if __name__ == "__main__":
main()