完成渠道模块的单元测试目录搭建,新增多个领域模型、端口、中间件、事件、服务以及基础设施层的单元测试文件,同时补充了conftest.py的环境变量配置,完善测试基础环境。
71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from yuxi.channel.domain.model.binding.channel_binding import ChannelBinding
|
|
|
|
|
|
class TestChannelBinding:
|
|
def test_basic_creation(self):
|
|
binding = ChannelBinding(
|
|
id=1,
|
|
channel_type="web",
|
|
account_id="user1",
|
|
group_id="",
|
|
agent_config_id=1,
|
|
)
|
|
assert binding.id == 1
|
|
assert binding.channel_type == "web"
|
|
assert binding.account_id == "user1"
|
|
assert binding.group_id == ""
|
|
assert binding.agent_config_id == 1
|
|
|
|
def test_creation_with_optional_fields(self):
|
|
binding = ChannelBinding(
|
|
id=1,
|
|
channel_type="web",
|
|
account_id="user1",
|
|
group_id="group1",
|
|
agent_config_id=1,
|
|
session_key_strategy="main",
|
|
)
|
|
assert binding.group_id == "group1"
|
|
assert binding.session_key_strategy == "main"
|
|
|
|
def test_to_dict(self):
|
|
binding = ChannelBinding(
|
|
id=1,
|
|
channel_type="web",
|
|
account_id="user1",
|
|
group_id="",
|
|
agent_config_id=1,
|
|
)
|
|
d = binding.to_dict()
|
|
assert d["id"] == 1
|
|
assert d["channel_type"] == "web"
|
|
assert d["account_id"] == "user1"
|
|
assert d["agent_config_id"] == 1
|
|
|
|
def test_from_dict(self):
|
|
d = {
|
|
"id": 1,
|
|
"channel_type": "web",
|
|
"account_id": "user1",
|
|
"group_id": "",
|
|
"agent_config_id": 1,
|
|
}
|
|
binding = ChannelBinding.from_dict(d)
|
|
assert binding.id == 1
|
|
assert binding.channel_type == "web"
|
|
assert binding.account_id == "user1"
|
|
|
|
def test_default_values(self):
|
|
binding = ChannelBinding(
|
|
id=1,
|
|
channel_type="web",
|
|
account_id="user1",
|
|
group_id="",
|
|
agent_config_id=1,
|
|
)
|
|
assert binding.session_key_strategy is None
|