mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +00:00
Add prototype of class-based handlers
This commit is contained in:
parent
2a731f7ce2
commit
b82a1a6fb0
11 changed files with 178 additions and 8 deletions
28
tests/test_dispatcher/test_handler/test_message.py
Normal file
28
tests/test_dispatcher/test_handler/test_message.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import datetime
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.types import Chat, Message, User
|
||||
from aiogram.dispatcher.handler.message import MessageHandler
|
||||
|
||||
|
||||
class MyHandler(MessageHandler):
|
||||
async def handle(self) -> Any:
|
||||
return self.event.text
|
||||
|
||||
|
||||
class TestClassBasedMessageHandler:
|
||||
@pytest.mark.asyncio
|
||||
async def test_message_handler(self):
|
||||
event = Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
text="test",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
)
|
||||
handler = MyHandler(event=event)
|
||||
|
||||
assert handler.from_user == event.from_user
|
||||
assert handler.chat == event.chat
|
||||
Loading…
Add table
Add a link
Reference in a new issue