def test___bool__(self): async def handler(): pass h1 = Handler(handler) h2 = Handler() assert bool(h1) is True assert bool(h2) is False
async def test___call__(self, mocker): h = Handler() mock_handler = mocker.patch.object(h, "handler", new=asynctest.CoroutineMock()) await h(param=123) mock_handler.assert_called_once_with(param=123)
def test___hash__(self, mocker): async def handler(): pass mock_hash = mocker.patch("aiotelegrambot.handler.hash", return_value=1) h = Handler(handler) assert hash(h) == mock_hash.return_value mock_hash.assert_called_once_with( (h.name, h.chat_type, h.incoming, h.content_type, h.rule))
def test___init__(self, mocker): async def handler(): pass chat_type = mocker.MagicMock() incoming = mocker.MagicMock() content_type = mocker.MagicMock() rule = mocker.MagicMock() h = Handler(handler, chat_type, incoming, content_type, rule) assert h.name == "handler" assert h.chat_type is chat_type assert h.incoming is incoming assert h.content_type is content_type assert h.rule is rule assert h.handler is handler
def test___repr__(self): h = Handler(rule="text") assert str(h) == "Handler(None, None, None, None, text)"
async def test___call___no_handler(self): h = Handler() await h(param=123)
def test_priority(self): h1 = Handler(rule=Text("text")) h2 = Handler(rule="text") assert h1.priority == Text.priority assert h2.priority == 1000000