test_07_module_live.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. """Swagger 模块 7(风控)— 真实联调(扫描使用真实 roomId)"""
  2. import uuid
  3. import pytest
  4. pytestmark = [pytest.mark.integration, pytest.mark.qiwei_live]
  5. @pytest.fixture(scope="module")
  6. def m07_keyword(api_session, live_room_id):
  7. suffix = uuid.uuid4().hex[:6]
  8. kw = api_session.assert_success(
  9. api_session.post(
  10. "/risk/keywords",
  11. json={
  12. "keyword": f"联调敏感词{suffix}",
  13. "category": "complaint",
  14. "severity": 3,
  15. "enabled": 1,
  16. "remark": "module7-live",
  17. },
  18. ),
  19. status=201,
  20. )
  21. yield {"id": kw["id"], "keyword": kw["keyword"], "room_id": live_room_id}
  22. api_session.assert_success(api_session.delete(f"/risk/keywords/{kw['id']}"))
  23. def test_m07_keywords_list(api, m07_keyword):
  24. listed = api.assert_success(api.get("/risk/keywords"))
  25. assert any(k["id"] == m07_keyword["id"] for k in listed)
  26. def test_m07_keywords_scan_real_room(api, m07_keyword):
  27. scan = api.assert_success(
  28. api.post(
  29. "/risk/keywords/scan",
  30. json={
  31. "content": f"测试{m07_keyword['keyword']}消息",
  32. "roomId": m07_keyword["room_id"],
  33. "messageId": 90001,
  34. },
  35. )
  36. )
  37. assert "hitCount" in scan or "hits" in scan or "alerts" in scan
  38. def test_m07_update_keyword(api, m07_keyword):
  39. updated = api.assert_success(
  40. api.put(
  41. f"/risk/keywords/{m07_keyword['id']}",
  42. json={"remark": "已更新"},
  43. )
  44. )
  45. assert updated["remark"] == "已更新"
  46. def test_m07_alerts_list(api):
  47. alerts = api.assert_success(api.get("/risk/alerts"))
  48. assert isinstance(alerts, list)
  49. def test_m07_handle_alert_if_any(api):
  50. alerts = api.assert_success(api.get("/risk/alerts"))
  51. if not alerts:
  52. pytest.skip("无预警可处理")
  53. handled = api.assert_success(
  54. api.put(
  55. f"/risk/alerts/{alerts[0]['id']}",
  56. json={"status": "handled", "handlerId": 1, "note": "模块7联调"},
  57. )
  58. )
  59. assert handled.get("status") in ("handled", "ignored")
  60. def test_m07_work_orders_list(api):
  61. orders = api.assert_success(api.get("/risk/work-orders"))
  62. assert isinstance(orders, list)
  63. def test_m07_update_work_order_if_any(api):
  64. orders = api.assert_success(api.get("/risk/work-orders"))
  65. if not orders:
  66. pytest.skip("无工单可更新")
  67. updated = api.assert_success(
  68. api.put(
  69. f"/risk/work-orders/{orders[0]['id']}",
  70. json={"status": "in_progress"},
  71. )
  72. )
  73. assert updated.get("status") == "in_progress"