21 lines
638 B
Python
21 lines
638 B
Python
|
|
"""WebSocket / 配额:轻量契约测试。"""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from unittest.mock import AsyncMock, MagicMock
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from app.features.conversation.ws.quota_guard import check_ws_quota
|
||
|
|
from app.features.quota.service import QuotaService
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.asyncio
|
||
|
|
async def test_check_ws_quota_delegates_to_quota_service() -> None:
|
||
|
|
qs = MagicMock(spec=QuotaService)
|
||
|
|
qs.check_can_send_message = AsyncMock(return_value=(True, ""))
|
||
|
|
ok, msg = await check_ws_quota(qs, "user-1", "free")
|
||
|
|
assert ok is True
|
||
|
|
assert msg == ""
|
||
|
|
qs.check_can_send_message.assert_awaited_once_with("user-1", "free")
|