61 lines
2.4 KiB
Python
61 lines
2.4 KiB
Python
|
|
"""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
|