新增了Twitch、Telegram、Discord、Slack、Mattermost、WeChat、Zalo等多渠道的单元测试用例,覆盖了令牌处理、速率限制、消息去重、会话解析、格式转换、安全策略等模块 同时在测试配置中添加了测试用的OpenAI API密钥环境变量
74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from yuxi.gateway.protocol.channels import ChannelLogoutRequest, ChannelStartRequest, ChannelStatusRequest
|
|
|
|
|
|
class TestChannelStatusRequest:
|
|
def test_default_construction(self):
|
|
req = ChannelStatusRequest()
|
|
assert req.channel_id is None
|
|
assert req.account_id is None
|
|
|
|
def test_with_channel_id(self):
|
|
req = ChannelStatusRequest(channel_id="telegram")
|
|
assert req.channel_id == "telegram"
|
|
assert req.account_id is None
|
|
|
|
def test_with_account_id(self):
|
|
req = ChannelStatusRequest(channel_id="telegram", account_id="acc-1")
|
|
assert req.account_id == "acc-1"
|
|
|
|
def test_json_roundtrip(self):
|
|
data = {"channel_id": "discord", "account_id": "acc-2"}
|
|
req = ChannelStatusRequest.model_validate(data)
|
|
dump = req.model_dump()
|
|
assert dump["channel_id"] == "discord"
|
|
assert dump["account_id"] == "acc-2"
|
|
|
|
|
|
class TestChannelStartRequest:
|
|
def test_channel_id_required(self):
|
|
with pytest.raises(ValidationError):
|
|
ChannelStartRequest()
|
|
|
|
def test_minimal_construction(self):
|
|
req = ChannelStartRequest(channel_id="telegram")
|
|
assert req.channel_id == "telegram"
|
|
assert req.account_id is None
|
|
|
|
def test_full_construction(self):
|
|
req = ChannelStartRequest(channel_id="slack", account_id="acc-3")
|
|
assert req.channel_id == "slack"
|
|
assert req.account_id == "acc-3"
|
|
|
|
def test_json_roundtrip(self):
|
|
data = {"channel_id": "whatsapp", "account_id": "acc-4"}
|
|
req = ChannelStartRequest.model_validate(data)
|
|
dump = req.model_dump()
|
|
assert dump["channel_id"] == "whatsapp"
|
|
|
|
|
|
class TestChannelLogoutRequest:
|
|
def test_channel_id_required(self):
|
|
with pytest.raises(ValidationError):
|
|
ChannelLogoutRequest()
|
|
|
|
def test_minimal_construction(self):
|
|
req = ChannelLogoutRequest(channel_id="telegram")
|
|
assert req.channel_id == "telegram"
|
|
assert req.logged_out is True
|
|
|
|
def test_full_construction(self):
|
|
req = ChannelLogoutRequest(channel_id="line", account_id="acc-5", logged_out=False)
|
|
assert req.channel_id == "line"
|
|
assert req.account_id == "acc-5"
|
|
assert req.logged_out is False
|
|
|
|
def test_json_roundtrip(self):
|
|
data = {"channel_id": "feishu", "account_id": "acc-6", "logged_out": True}
|
|
req = ChannelLogoutRequest.model_validate(data)
|
|
dump = req.model_dump()
|
|
assert dump["logged_out"] is True |