ForcePilot/backend/test/unit/channels/plugins/dingtalk/conftest.py
Kris 532e7c59ec test: add and fix multi-channel unit tests
1. 新增QQBot、Wecom、Dingtalk、Instagram、WechatMp等渠道的单元测试夹具与测试用例
2. 修复WechatILink的缓存键顺序与测试用例
3. 补全Feishu适配器的日志断言与测试逻辑
4. 清理WechatILink冗余的clear_context_token测试代码
2026-07-08 22:59:24 +08:00

72 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""channels plugins/dingtalk 层单元测试共享 fixture。
提供 ``fake_dingtalk_client`` 桩,模拟 ``DingTalkClient``
``yuxi.channels.plugins.dingtalk.dingtalk_client.DingTalkClient``)。
钉钉适配器测试通过此桩注入客户端依赖,不发起真实 HTTP 请求。
桩使用 ``AsyncMock()``,预设主要方法返回值(空 dict / 空 bytes / token
元组),调用方可按需覆盖。方法签名以 ``DingTalkClient`` 实现为准。单文件
独有的 helper 应保留在对应测试文件内(见 testing-guidelines.md
"""
from __future__ import annotations
from unittest.mock import AsyncMock
import pytest
@pytest.fixture
def fake_dingtalk_client() -> AsyncMock:
"""DingTalkClient 桩。
``AsyncMock()`` 模拟 ``DingTalkClient``,预设主要方法返回值:
- ``get_access_token`` 返回 ``("fake-token", 7200)``
- ``send_oto_message`` / ``send_group_message`` 返回 ``{"messageId": "msg-1", "processQueryKey": "pqk-1"}``
- ``recall_oto_message`` / ``recall_group_message`` 返回 ``{}``
- ``post_session_webhook`` 返回 ``{}``
- ``send_interactive_card`` / ``update_interactive_card`` 返回 ``{}``
- ``download_file`` 返回 ``b""``
- 通讯录 API``get_userid_by_unionid`` / ``get_user_detail_by_userid`` /
``search_users`` / ``get_group_members`` / ``get_group_detail`` /
``get_group_list``)返回 ``{}``
- ``get_stream_endpoint`` 返回 ``{"connectionId": "conn-1", "endpoint": "wss://fake"}``
- ``request`` 返回 ``{}``。
"""
client = AsyncMock()
# Token 管理
client.get_access_token.return_value = ("fake-token", 7200)
# 通用请求
client.request.return_value = {}
# 机器人消息 API
client.send_oto_message.return_value = {
"messageId": "msg-1",
"processQueryKey": "pqk-1",
}
client.send_group_message.return_value = {
"messageId": "msg-1",
"processQueryKey": "pqk-1",
}
client.recall_oto_message.return_value = {}
client.recall_group_message.return_value = {}
# HTTP 模式 sessionWebhook
client.post_session_webhook.return_value = {}
# 互动卡片 API
client.send_interactive_card.return_value = {}
client.update_interactive_card.return_value = {}
# 媒体下载
client.download_file.return_value = b""
# 通讯录 API
client.get_userid_by_unionid.return_value = {}
client.get_user_detail_by_userid.return_value = {}
client.search_users.return_value = {}
client.get_group_members.return_value = {}
client.get_group_detail.return_value = {}
client.get_group_list.return_value = {}
# Stream 接入
client.get_stream_endpoint.return_value = {
"connectionId": "conn-1",
"endpoint": "wss://fake-endpoint",
}
return client