e2e_mode3_full.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """模式 3 样本闭环:Mock 端点可读,且不触碰 WMS_API / TEST_INBOUND_ERP。
  2. 宿主未启动时本脚本只验证样本与 Mock,不把未跑通的推数记为通过。
  3. 用法:先在 doc/db/mdp/mock_api 启动 mock_server(8018),再执行本脚本。
  4. """
  5. from __future__ import annotations
  6. import json
  7. import sys
  8. import urllib.request
  9. from pathlib import Path
  10. MOCK = "http://127.0.0.1:8018"
  11. TOKEN = "uat-mock-token"
  12. ROOT = Path(__file__).resolve().parents[1] / "mock_api"
  13. PATHS = [
  14. "/api/inventory-txn",
  15. "/api/inventory-balance-monthly",
  16. "/api/fqc-task",
  17. "/api/work-order-bom",
  18. "/api/mes/report",
  19. "/api/sales-order",
  20. "/api/item",
  21. ]
  22. def main() -> int:
  23. endpoints = json.loads((ROOT / "endpoints.json").read_text(encoding="utf-8"))
  24. missing = [p for p in PATHS if p not in endpoints]
  25. if missing:
  26. print("endpoints missing:", ", ".join(missing))
  27. return 1
  28. ok = 0
  29. for path in PATHS:
  30. req = urllib.request.Request(
  31. MOCK + path,
  32. headers={"Authorization": f"Bearer {TOKEN}"},
  33. )
  34. try:
  35. with urllib.request.urlopen(req, timeout=5) as resp:
  36. body = json.loads(resp.read().decode("utf-8"))
  37. except Exception as ex:
  38. print(f"FAIL {path}: {ex}")
  39. print("Mock 未启动或样本不可读。推数入中立层需要宿主,本次不记为通过。")
  40. return 2
  41. rows = body.get("data", {}).get("list")
  42. if not isinstance(rows, list) or not rows or "bizKey" not in rows[0]:
  43. print(f"FAIL {path}: data.list 无 bizKey")
  44. return 1
  45. ok += 1
  46. print(f"OK {path} rows={len(rows)}")
  47. print(f"mock samples {ok}/{len(PATHS)}. 宿主推数闭环未在本脚本内执行。")
  48. return 0
  49. if __name__ == "__main__":
  50. sys.exit(main())