_verify_s1_s4_continue_s4fix.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env python3
  2. """Corrected S4 + a few remaining smoke APIs after path fix."""
  3. import json
  4. import urllib.request
  5. from gmssl import sm2
  6. BASE = "http://127.0.0.1:5005"
  7. TENANT = 797403760988229
  8. PK = "84C7466D950E120E5ECE5DD85D0C90EAA85081A3A2BD7C57AE6DC822EFCCBD66620C67B0103FC8DD280E36C3B282977B722AAEC3C56518EDCEBAFB72C5A05312"
  9. def http(method, path, body=None, token=None):
  10. headers = {"Content-Type": "application/json", "Accept": "application/json"}
  11. if token:
  12. headers["Authorization"] = f"Bearer {token}"
  13. data = None if body is None else json.dumps(body).encode()
  14. req = urllib.request.Request(BASE + path, data=data, headers=headers, method=method)
  15. try:
  16. with urllib.request.urlopen(req, timeout=120) as r:
  17. raw = r.read().decode()
  18. return r.status, json.loads(raw) if raw else {}
  19. except Exception as e:
  20. if hasattr(e, "read"):
  21. raw = e.read().decode("utf-8", "replace")
  22. try:
  23. return getattr(e, "code", 0), json.loads(raw)
  24. except Exception:
  25. return getattr(e, "code", 0), {"raw": raw[:400]}
  26. return 0, {"error": str(e)}
  27. crypt = sm2.CryptSM2(public_key=PK, private_key=None, mode=1)
  28. pwd = crypt.encrypt(b"1234567890dop").hex()
  29. st, body = http("POST", "/api/sysAuth/login", {"account": "AIDOPDemo", "password": pwd, "tenantId": str(TENANT)})
  30. token = (body.get("result") or {}).get("accessToken")
  31. assert token, body
  32. apis = [
  33. ("GET", "/api/ProcurementExecution/supplier-shipment/list?page=1&pageSize=5"),
  34. ("GET", "/api/ProcurementExecution/supplier-delivery/list?page=1&pageSize=5"),
  35. ("GET", "/api/ProcurementExecution/supplier-shortage-kanban/list?page=1&pageSize=5"),
  36. ("GET", "/api/ProcurementExecution/iqc-return/list?page=1&pageSize=5"),
  37. ("GET", "/api/ProcurementExecution/purchase-return/list?page=1&pageSize=5"),
  38. ("GET", "/api/WorkOrder/dispatch/list?page=1&pageSize=5"),
  39. ("GET", "/api/Production/daily-plan/list?page=1&pageSize=5"),
  40. ("GET", "/api/Supply/work-order-material-readiness/list?page=1&pageSize=5&keyword=M000000005"),
  41. ]
  42. out = []
  43. for method, path in apis:
  44. st, b = http(method, path, token=token)
  45. res = b.get("result", b) if isinstance(b, dict) else b
  46. brief = {}
  47. if isinstance(res, dict):
  48. for k in ("total", "list", "message", "page"):
  49. if k in res:
  50. brief[k] = len(res[k]) if k == "list" and isinstance(res[k], list) else res[k]
  51. if not brief:
  52. brief = {"keys": list(res.keys())[:8], "code": b.get("code"), "msg": str(b.get("message") or "")[:160]}
  53. out.append(
  54. {
  55. "api": f"{method} {path.split('?')[0]}",
  56. "http": st,
  57. "ok": st == 200 and (not isinstance(b, dict) or b.get("code", 200) in (200, None)),
  58. "brief": brief,
  59. "err": (b.get("message") if isinstance(b, dict) else None) or (b.get("error") if isinstance(b, dict) else None),
  60. }
  61. )
  62. path = r"d:\Projects\Ai-DOP\SourceCode\ZZYDOP\doc\_verify_s1_s4_continue_s4fix_result.json"
  63. with open(path, "w", encoding="utf-8") as f:
  64. json.dump(out, f, ensure_ascii=False, indent=2, default=str)
  65. print(json.dumps(out, ensure_ascii=False, indent=2, default=str))