test_03_module_live.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. """
  2. Swagger 模块 3(人员)— 真实联调
  3. 使用 backend/.env 的 QIWEI_GUID 回填人员,并调用 QiWe 校验在线状态。
  4. 覆盖 api-docs 中 6 个接口。
  5. """
  6. from __future__ import annotations
  7. import uuid
  8. import pytest
  9. from load_env import load_backend_env
  10. pytestmark = [pytest.mark.integration, pytest.mark.qiwei_live]
  11. @pytest.fixture(scope="module")
  12. def live_staff_record(api_session, live_guid):
  13. """创建人员 → 绑定真实 guid → 用例结束后删除"""
  14. env = load_backend_env()
  15. suffix = uuid.uuid4().hex[:8]
  16. phone = f"139{suffix[:8]}"
  17. created = api_session.assert_success(
  18. api_session.post(
  19. "/staff",
  20. json={
  21. "name": f"联调人员_{suffix}",
  22. "role": "operator",
  23. "storeId": 1,
  24. "phone": phone,
  25. },
  26. ),
  27. status=201,
  28. )
  29. staff_id = created["id"]
  30. updated = api_session.assert_success(
  31. api_session.put(
  32. f"/staff/{staff_id}",
  33. json={"guid": live_guid, "status": 1},
  34. )
  35. )
  36. assert updated["guid"] == live_guid
  37. yield {"id": staff_id, "phone": phone, "name": created["name"], "guid": live_guid}
  38. api_session.assert_success(api_session.delete(f"/staff/{staff_id}"))
  39. def test_m03_create_staff(live_staff_record):
  40. assert live_staff_record["id"] > 0
  41. assert live_staff_record["guid"]
  42. def test_m03_list_staff(api, live_staff_record):
  43. listed = api.assert_success(
  44. api.get(
  45. "/staff",
  46. params={"role": "operator", "storeId": 1, "status": 1},
  47. )
  48. )
  49. assert any(s["id"] == live_staff_record["id"] for s in listed)
  50. def test_m03_staff_detail(api, live_staff_record):
  51. detail = api.assert_success(api.get(f"/staff/{live_staff_record['id']}"))
  52. assert detail["guid"] == live_staff_record["guid"]
  53. assert detail["phone"] == live_staff_record["phone"]
  54. def test_m03_active_guids(api, live_guid, live_staff_record):
  55. data = api.assert_success(api.get("/staff/active-guids"))
  56. assert live_guid in data["guids"]
  57. assert data["count"] >= 1
  58. def test_m03_qiwei_online_matches_staff(api, live_guid, live_staff_record):
  59. """人员 guid 与 QiWe 在线接口一致(跨模块真实校验)"""
  60. online = api.assert_success(api.get(f"/qiwei/staff/{live_guid}/status"))
  61. assert online.get("guid") == live_guid or online.get("userId")
  62. assert online["userOnlineStatus"] in (1, 2)
  63. assert online.get("nickname") or online.get("userId")
  64. def test_m03_update_staff(api, live_staff_record):
  65. updated = api.assert_success(
  66. api.put(
  67. f"/staff/{live_staff_record['id']}",
  68. json={"name": live_staff_record["name"] + "_已更新"},
  69. )
  70. )
  71. assert updated["name"].endswith("_已更新")