test_11_module_live.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. """Swagger 模块 11(经营)— 真实联调(客户/订单绑定真实 roomId)"""
  2. from __future__ import annotations
  3. import uuid
  4. import pytest
  5. pytestmark = [pytest.mark.integration, pytest.mark.qiwei_live]
  6. @pytest.fixture(scope="module")
  7. def m11_customer(api_session, live_room_id):
  8. suffix = uuid.uuid4().hex[:8]
  9. customer = api_session.assert_success(
  10. api_session.post(
  11. "/sales/customers",
  12. json={
  13. "name": f"联调客户_{suffix}",
  14. "phone": f"138{suffix[:8]}",
  15. "source": "group",
  16. "roomId": live_room_id,
  17. },
  18. ),
  19. status=201,
  20. )
  21. return {"customer": customer, "room_id": live_room_id}
  22. def test_m11_leads_create_and_list(api, uid):
  23. lead = api.assert_success(
  24. api.post(
  25. "/sales/leads",
  26. json={
  27. "salespersonId": 1,
  28. "recordDate": "2026-05-21",
  29. "addCount": 3,
  30. "remark": f"live-{uid}",
  31. },
  32. ),
  33. status=201,
  34. )
  35. assert lead["addCount"] == 3
  36. listed = api.assert_success(api.get("/sales/leads"))
  37. assert any(l.get("remark") == f"live-{uid}" for l in listed)
  38. def test_m11_orders_create_and_list(api, m11_customer, uid):
  39. cust_id = m11_customer["customer"]["id"]
  40. order = api.assert_success(
  41. api.post(
  42. "/sales/orders",
  43. json={
  44. "salespersonId": 1,
  45. "customerId": cust_id,
  46. "amount": 88000,
  47. "orderDate": "2026-05-20",
  48. "source": "group",
  49. "roomId": m11_customer["room_id"],
  50. },
  51. ),
  52. status=201,
  53. )
  54. assert order["roomId"] == m11_customer["room_id"]
  55. listed = api.assert_success(api.get("/sales/orders"))
  56. assert any(o["id"] == order["id"] for o in listed)
  57. def test_m11_customers_list(api, m11_customer):
  58. listed = api.assert_success(api.get("/sales/customers"))
  59. assert any(c["id"] == m11_customer["customer"]["id"] for c in listed)
  60. def test_m11_customer_detail(api, m11_customer):
  61. cid = m11_customer["customer"]["id"]
  62. detail = api.assert_success(api.get(f"/sales/customers/{cid}"))
  63. assert detail["roomId"] == m11_customer["room_id"]
  64. def test_m11_customer_update(api, m11_customer):
  65. cid = m11_customer["customer"]["id"]
  66. updated = api.assert_success(
  67. api.put(f"/sales/customers/{cid}", json={"remark": "模块11联调"})
  68. )
  69. assert updated.get("remark") == "模块11联调"
  70. def test_m11_follow_ups(api, m11_customer):
  71. cid = m11_customer["customer"]["id"]
  72. follow = api.assert_success(
  73. api.post(
  74. f"/sales/customers/{cid}/follow-ups",
  75. json={
  76. "customerId": cid,
  77. "followerId": 1,
  78. "followDate": "2026-05-21",
  79. "method": "wechat",
  80. "content": "真实群跟进",
  81. },
  82. ),
  83. status=201,
  84. )
  85. assert follow["customerId"] == cid
  86. listed = api.assert_success(api.get(f"/sales/customers/{cid}/follow-ups"))
  87. assert len(listed) >= 1
  88. def test_m11_live_stats(api, uid):
  89. stat = api.assert_success(
  90. api.post(
  91. "/sales/live-stats",
  92. json={
  93. "liveSessionId": f"live-session-{uid}",
  94. "title": f"联调直播_{uid}",
  95. "liveDate": "2026-05-21",
  96. "viewerCount": 256,
  97. },
  98. ),
  99. status=201,
  100. )
  101. assert stat["viewerCount"] == 256
  102. listed = api.assert_success(api.get("/sales/live-stats"))
  103. assert any(s["id"] == stat["id"] for s in listed)