test_12_module_live.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. """Swagger 模块 12(工作台)— 真实联调(真实群名模板 + 可选 QiWe 通知)"""
  2. from __future__ import annotations
  3. import pytest
  4. from load_env import load_backend_env
  5. pytestmark = [pytest.mark.integration, pytest.mark.qiwei_live]
  6. @pytest.fixture(scope="session")
  7. def m12_staff_id(api_session, live_guid: str) -> int:
  8. digits = "".join(c for c in live_guid if c.isdigit())[:8] or "00000001"
  9. phone = f"137{digits}"
  10. created = api_session.assert_success(
  11. api_session.post(
  12. "/staff",
  13. json={
  14. "name": "模块12联调员",
  15. "role": "operator",
  16. "storeId": 1,
  17. "phone": phone,
  18. },
  19. ),
  20. status=201,
  21. )
  22. staff_id = created["id"]
  23. api_session.assert_success(
  24. api_session.put(f"/staff/{staff_id}", json={"guid": live_guid, "status": 1})
  25. )
  26. return staff_id
  27. def test_m12_workbench(api):
  28. home = api.assert_success(api.get("/workbench", params={"role": "manager"}))
  29. assert isinstance(home, dict)
  30. def test_m12_notifications_list(api):
  31. notifs = api.assert_success(api.get("/notifications"))
  32. assert isinstance(notifs, list)
  33. def test_m12_notification_template_real_room(api, live_room_ids, live_rooms_seeded):
  34. room = api.assert_success(api.get(f"/rooms/{live_room_ids[0]}"))
  35. tpl = api.assert_success(
  36. api.get(
  37. "/notifications/template",
  38. params={"issueType": "missing_doc", "roomName": room["roomName"]},
  39. )
  40. )
  41. assert room["roomName"] in tpl["content"]
  42. assert "整改" in tpl["title"]
  43. def test_m12_send_notification_local(api, m12_staff_id):
  44. """未开 QIWEI_LIVE_NOTIFY 时仍走本地记录通道"""
  45. env = load_backend_env()
  46. if env.get("QIWEI_LIVE_NOTIFY", "").strip() == "1":
  47. pytest.skip("已开启真实通知,改由 test_m12_send_notification_qiwe 覆盖")
  48. sent = api.assert_success(
  49. api.post(
  50. "/notifications/send",
  51. json={
  52. "type": "compliance",
  53. "receiverId": m12_staff_id,
  54. "title": "模块12联调通知",
  55. "content": "本地通道测试",
  56. "refId": 1,
  57. },
  58. ),
  59. status=201,
  60. )
  61. assert sent.get("id") is not None
  62. def test_m12_send_notification_qiwe(api, live_guid, m12_staff_id, live_room_ids):
  63. env = load_backend_env()
  64. if env.get("QIWEI_LIVE_NOTIFY", "").strip() != "1":
  65. pytest.skip("未开启真实企微通知:.env 设置 QIWEI_LIVE_NOTIFY=1")
  66. room = api.assert_success(api.get(f"/rooms/{live_room_ids[0]}"))
  67. tpl = api.assert_success(
  68. api.get(
  69. "/notifications/template",
  70. params={"issueType": "missing_doc", "roomName": room["roomName"]},
  71. )
  72. )
  73. sent = api.assert_success(
  74. api.post(
  75. "/notifications/send",
  76. json={
  77. "type": "compliance",
  78. "receiverId": m12_staff_id,
  79. "title": tpl["title"],
  80. "content": tpl["content"] + " [模块12联调]",
  81. "refId": 1,
  82. "guid": live_guid,
  83. "toId": live_room_ids[0],
  84. },
  85. ),
  86. status=201,
  87. )
  88. assert sent.get("channel") == "qiwe"
  89. assert sent.get("status") == "sent"
  90. def test_m12_audit_logs(api):
  91. logs = api.assert_success(api.get("/audit-logs", params={"limit": 10}))
  92. assert isinstance(logs, list)