ForcePilot/backend/test/unit/channels/plugins/wecom/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

61 lines
2.4 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/wecom 层单元测试共享 fixture。
提供 ``fake_wecom_client`` 桩,模拟 ``WecomClient``
``yuxi.channels.channels.plugins.wecom.wecom_client.WecomClient``)。
企业微信适配器测试通过此桩注入客户端依赖,不发起真实 HTTP 请求。
桩使用 ``AsyncMock()``,预设主要方法返回值(空 dict / 空 bytes / token
字符串),调用方可按需覆盖。方法签名以 ``WecomClient`` 实现为准。单文件
独有的 helper 应保留在对应测试文件内(见 testing-guidelines.md
"""
from __future__ import annotations
from unittest.mock import AsyncMock
import pytest
@pytest.fixture
def fake_wecom_client() -> AsyncMock:
"""WecomClient 桩。
``AsyncMock()`` 模拟 ``WecomClient``,预设主要方法返回值:
- ``get_access_token`` 返回 ``"fake-token"``
- ``verify_token`` 返回 ``True``
- ``send_message`` / ``recall_message`` / ``update_template_card`` 等
应用消息 API 返回 ``{}``
- ``upload_media`` / ``download_media`` 返回 ``{}`` / ``b""``
- 通讯录 / 客户联系 / 客服 / OAuth API 返回 ``{}``。
"""
client = AsyncMock()
# Token 管理
client.get_access_token.return_value = "fake-token"
client.get_token_with_credentials.return_value = ("fake-token", 7200)
client.verify_token.return_value = True
# 应用消息 API
client.send_message.return_value = {"msgid": "msg-1"}
client.recall_message.return_value = {}
client.update_template_card.return_value = {}
# 媒体上传/下载 API
client.upload_media.return_value = {"media_id": "media-1"}
client.download_media.return_value = b""
# 通讯录 API
client.get_user.return_value = {}
client.list_user_ids.return_value = {}
client.convert_to_openid.return_value = {}
# 客户联系 API
client.get_external_contact.return_value = {}
client.list_external_contacts.return_value = {}
client.list_group_chats.return_value = {}
client.get_group_chat.return_value = {}
client.unionid_to_external_userid.return_value = {}
# 微信客服 API
client.send_kf_message.return_value = {}
client.list_kf_accounts.return_value = {}
# OAuth API
client.get_oauth_user_info.return_value = {}
client.get_user_detail.return_value = {}
client.get_api_domain_ip.return_value = {}
return client