1. 删除了 test/unit/external_systems/framework/ 下的废弃空测试目录 2. 修复多处测试断言逻辑、参数传递与测试数据构造 3. 新增日志级别、缓存令牌、流事件等DTO单元测试 4. 补充路由绑定、会话仓储、outbox仓储的测试覆盖 5. 更新测试用例中的异常类型、参数校验与业务逻辑断言
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
"""cache.py DTO 单元测试。
|
|
|
|
覆盖 ``LockToken`` 的字段赋值、默认值、不可变语义与 ``__post_init__``
|
|
校验逻辑。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import dataclasses
|
|
from datetime import datetime
|
|
|
|
import pytest
|
|
from yuxi.channels.contract.dtos.cache import LockToken
|
|
from yuxi.channels.contract.errors import ValidationError
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestLockToken:
|
|
"""锁令牌 DTO 测试。"""
|
|
|
|
def test_fields_are_assigned(self):
|
|
# Arrange
|
|
now = datetime(2026, 1, 1, 12, 0, 0)
|
|
# Act
|
|
token = LockToken(key="lock:abc", value="token-123", expires_at=now)
|
|
# Assert
|
|
assert token.key == "lock:abc"
|
|
assert token.value == "token-123"
|
|
assert token.expires_at is now
|
|
|
|
def test_is_frozen(self):
|
|
# Arrange
|
|
now = datetime(2026, 1, 1, 12, 0, 0)
|
|
token = LockToken(key="lock:abc", value="token-123", expires_at=now)
|
|
# Act / Assert
|
|
with pytest.raises(dataclasses.FrozenInstanceError):
|
|
token.key = "other" # type: ignore[misc]
|
|
|
|
def test_empty_key_raises_validation_error(self):
|
|
# Arrange
|
|
now = datetime(2026, 1, 1, 12, 0, 0)
|
|
# Act / Assert - key 为空字符串应抛出 ValidationError
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
LockToken(key="", value="token-123", expires_at=now)
|
|
assert exc_info.value.field == "key"
|
|
|
|
def test_empty_value_raises_validation_error(self):
|
|
# Arrange
|
|
now = datetime(2026, 1, 1, 12, 0, 0)
|
|
# Act / Assert - value 为空字符串应抛出 ValidationError
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
LockToken(key="lock:abc", value="", expires_at=now)
|
|
assert exc_info.value.field == "value"
|