| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- """模式 3 样本闭环:Mock 端点可读,且不触碰 WMS_API / TEST_INBOUND_ERP。
- 宿主未启动时本脚本只验证样本与 Mock,不把未跑通的推数记为通过。
- 用法:先在 doc/db/mdp/mock_api 启动 mock_server(8018),再执行本脚本。
- """
- from __future__ import annotations
- import json
- import sys
- import urllib.request
- from pathlib import Path
- MOCK = "http://127.0.0.1:8018"
- TOKEN = "uat-mock-token"
- ROOT = Path(__file__).resolve().parents[1] / "mock_api"
- PATHS = [
- "/api/inventory-txn",
- "/api/inventory-balance-monthly",
- "/api/fqc-task",
- "/api/work-order-bom",
- "/api/mes/report",
- "/api/sales-order",
- "/api/item",
- ]
- def main() -> int:
- endpoints = json.loads((ROOT / "endpoints.json").read_text(encoding="utf-8"))
- missing = [p for p in PATHS if p not in endpoints]
- if missing:
- print("endpoints missing:", ", ".join(missing))
- return 1
- ok = 0
- for path in PATHS:
- req = urllib.request.Request(
- MOCK + path,
- headers={"Authorization": f"Bearer {TOKEN}"},
- )
- try:
- with urllib.request.urlopen(req, timeout=5) as resp:
- body = json.loads(resp.read().decode("utf-8"))
- except Exception as ex:
- print(f"FAIL {path}: {ex}")
- print("Mock 未启动或样本不可读。推数入中立层需要宿主,本次不记为通过。")
- return 2
- rows = body.get("data", {}).get("list")
- if not isinstance(rows, list) or not rows or "bizKey" not in rows[0]:
- print(f"FAIL {path}: data.list 无 bizKey")
- return 1
- ok += 1
- print(f"OK {path} rows={len(rows)}")
- print(f"mock samples {ok}/{len(PATHS)}. 宿主推数闭环未在本脚本内执行。")
- return 0
- if __name__ == "__main__":
- sys.exit(main())
|