41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from yuxi.channels.policy.heartbeat import BaseHeartbeatAdapter
|
||
|
|
|
||
|
|
|
||
|
|
def _make_demo():
|
||
|
|
class DemoHeartbeat(BaseHeartbeatAdapter):
|
||
|
|
async def check_ready(self):
|
||
|
|
return True
|
||
|
|
|
||
|
|
async def send_typing(self, chat_id: str):
|
||
|
|
pass
|
||
|
|
|
||
|
|
async def clear_typing(self, chat_id: str):
|
||
|
|
pass
|
||
|
|
|
||
|
|
return DemoHeartbeat()
|
||
|
|
|
||
|
|
|
||
|
|
class TestBaseHeartbeatAdapter:
|
||
|
|
def test_cannot_instantiate_abstract(self):
|
||
|
|
with pytest.raises(TypeError):
|
||
|
|
BaseHeartbeatAdapter()
|
||
|
|
|
||
|
|
def test_can_instantiate_concrete_impl(self):
|
||
|
|
instance = _make_demo()
|
||
|
|
assert isinstance(instance, BaseHeartbeatAdapter)
|
||
|
|
|
||
|
|
@pytest.mark.asyncio
|
||
|
|
async def test_resolve_recipients_default(self):
|
||
|
|
instance = _make_demo()
|
||
|
|
result = await instance.resolve_recipients("chat-123")
|
||
|
|
assert result == ["chat-123"]
|
||
|
|
|
||
|
|
@pytest.mark.asyncio
|
||
|
|
async def test_on_unhealthy_noop(self):
|
||
|
|
instance = _make_demo()
|
||
|
|
result = await instance.on_unhealthy("chat-123")
|
||
|
|
assert result is None
|