ForcePilot/backend/test/unit/channel/startup/test_domain_events.py
Kris 6c95dc006a test: 新增渠道模块全链路单元测试用例与目录结构
完成渠道模块的单元测试目录搭建,新增多个领域模型、端口、中间件、事件、服务以及基础设施层的单元测试文件,同时补充了conftest.py的环境变量配置,完善测试基础环境。
2026-05-30 21:55:35 +08:00

106 lines
2.9 KiB
Python

from __future__ import annotations
import pytest
from yuxi.channel.domain.event.message_received import MessageReceived
from yuxi.channel.domain.event.message_blocked import MessageBlocked
from yuxi.channel.domain.event.message_replied import MessageReplied
from yuxi.channel.domain.event.agent_error import AgentError
from yuxi.channel.domain.event.gateway_shutdown import GatewayShutdown
class TestMessageReceived:
def test_creation(self):
event = MessageReceived(
message_id="msg123",
channel_type="web",
sender_id="user1",
content="Hello",
)
assert event.message_id == "msg123"
assert event.channel_type == "web"
assert event.sender_id == "user1"
assert event.content == "Hello"
def test_to_dict(self):
event = MessageReceived(
message_id="msg123",
channel_type="web",
sender_id="user1",
content="Hello",
)
d = event.to_dict()
assert d["message_id"] == "msg123"
assert d["channel_type"] == "web"
class TestMessageBlocked:
def test_creation(self):
event = MessageBlocked(
message_id="msg123",
channel_type="web",
reason="rate_limit",
)
assert event.message_id == "msg123"
assert event.reason == "rate_limit"
def test_to_dict(self):
event = MessageBlocked(
message_id="msg123",
channel_type="web",
reason="rate_limit",
)
d = event.to_dict()
assert d["reason"] == "rate_limit"
class TestMessageReplied:
def test_creation(self):
event = MessageReplied(
message_id="msg123",
channel_type="web",
reply_content="Hello back",
)
assert event.message_id == "msg123"
assert event.reply_content == "Hello back"
def test_to_dict(self):
event = MessageReplied(
message_id="msg123",
channel_type="web",
reply_content="Hello back",
)
d = event.to_dict()
assert d["reply_content"] == "Hello back"
class TestAgentError:
def test_creation(self):
event = AgentError(
message_id="msg123",
channel_type="web",
error="timeout",
)
assert event.message_id == "msg123"
assert event.error == "timeout"
def test_to_dict(self):
event = AgentError(
message_id="msg123",
channel_type="web",
error="timeout",
)
d = event.to_dict()
assert d["error"] == "timeout"
class TestGatewayShutdown:
def test_creation(self):
event = GatewayShutdown(reason="maintenance")
assert event.reason == "maintenance"
def test_to_dict(self):
event = GatewayShutdown(reason="maintenance")
d = event.to_dict()
assert d["reason"] == "maintenance"