"""Swagger 模块 12(工作台)— 真实联调(真实群名模板 + 可选 QiWe 通知)""" from __future__ import annotations import pytest from load_env import load_backend_env pytestmark = [pytest.mark.integration, pytest.mark.qiwei_live] @pytest.fixture(scope="session") def m12_staff_id(api_session, live_guid: str) -> int: digits = "".join(c for c in live_guid if c.isdigit())[:8] or "00000001" phone = f"137{digits}" created = api_session.assert_success( api_session.post( "/staff", json={ "name": "模块12联调员", "role": "operator", "storeId": 1, "phone": phone, }, ), status=201, ) staff_id = created["id"] api_session.assert_success( api_session.put(f"/staff/{staff_id}", json={"guid": live_guid, "status": 1}) ) return staff_id def test_m12_workbench(api): home = api.assert_success(api.get("/workbench", params={"role": "manager"})) assert isinstance(home, dict) def test_m12_notifications_list(api): notifs = api.assert_success(api.get("/notifications")) assert isinstance(notifs, list) def test_m12_notification_template_real_room(api, live_room_ids, live_rooms_seeded): room = api.assert_success(api.get(f"/rooms/{live_room_ids[0]}")) tpl = api.assert_success( api.get( "/notifications/template", params={"issueType": "missing_doc", "roomName": room["roomName"]}, ) ) assert room["roomName"] in tpl["content"] assert "整改" in tpl["title"] def test_m12_send_notification_local(api, m12_staff_id): """未开 QIWEI_LIVE_NOTIFY 时仍走本地记录通道""" env = load_backend_env() if env.get("QIWEI_LIVE_NOTIFY", "").strip() == "1": pytest.skip("已开启真实通知,改由 test_m12_send_notification_qiwe 覆盖") sent = api.assert_success( api.post( "/notifications/send", json={ "type": "compliance", "receiverId": m12_staff_id, "title": "模块12联调通知", "content": "本地通道测试", "refId": 1, }, ), status=201, ) assert sent.get("id") is not None def test_m12_send_notification_qiwe(api, live_guid, m12_staff_id, live_room_ids): env = load_backend_env() if env.get("QIWEI_LIVE_NOTIFY", "").strip() != "1": pytest.skip("未开启真实企微通知:.env 设置 QIWEI_LIVE_NOTIFY=1") room = api.assert_success(api.get(f"/rooms/{live_room_ids[0]}")) tpl = api.assert_success( api.get( "/notifications/template", params={"issueType": "missing_doc", "roomName": room["roomName"]}, ) ) sent = api.assert_success( api.post( "/notifications/send", json={ "type": "compliance", "receiverId": m12_staff_id, "title": tpl["title"], "content": tpl["content"] + " [模块12联调]", "refId": 1, "guid": live_guid, "toId": live_room_ids[0], }, ), status=201, ) assert sent.get("channel") == "qiwe" assert sent.get("status") == "sent" def test_m12_audit_logs(api): logs = api.assert_success(api.get("/audit-logs", params={"limit": 10})) assert isinstance(logs, list)