53 lines
2.5 KiB
Python
53 lines
2.5 KiB
Python
"""实测渠道只读接口及必然拒绝的无效创建请求,不写入实际平台渠道。"""
|
|
|
|
import argparse
|
|
import json
|
|
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 = []
|
|
|
|
def call(method, path, expected=0, body=None):
|
|
request = urllib.request.Request(args.base_url + path, method=method,
|
|
headers={"x-token": token, "Content-Type": "application/json"},
|
|
data=json.dumps(body).encode() if body is not None else None)
|
|
with urllib.request.urlopen(request, timeout=30) as response:
|
|
payload = json.load(response)
|
|
item = {"method": method, "path": path, "http": response.status, "code": payload.get("code"),
|
|
"msg": payload.get("msg"), "passed": response.status == 200 and payload.get("code") == expected}
|
|
data = payload.get("data", {})
|
|
if isinstance(data, dict) and "rows" in data:
|
|
item.update(total=data["total"], available=data.get("available"))
|
|
if isinstance(data, list):
|
|
item["rows"] = len(data)
|
|
checks.append(item)
|
|
print(json.dumps(item, ensure_ascii=False))
|
|
return data
|
|
|
|
data = call("GET", "/sw/promote/list?pageNum=1&pageSize=10")
|
|
call("GET", "/sw/promote/list?sourceDb=lx,hw&lockStatus=-1&promoteLevel=1")
|
|
call("GET", "/sw/promote/list?busierAccount=does-not-exist")
|
|
for source in ["lx", "hw", "yq"]:
|
|
call("GET", "/sw/promote/bindOptions?sourceDb=" + source)
|
|
call("GET", "/sw/promote/game-distribution?sourceDb=lx&promoteId=0", expected=7)
|
|
if isinstance(data, dict) and data.get("available") is False:
|
|
call("GET", "/sw/promote/game-distribution?sourceDb=lx&promoteId=1", expected=7)
|
|
call("POST", "/sw/promote", expected=7, body={})
|
|
report = {"scope": "当前 sw7 实际登录会话;只读查询和无效创建。完整查询、偏好、游戏分布及源库创建已在隔离数据库通过 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()
|