mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Dev 3.x flat package (#961)
* Move packages * Added changelog * Update examples/echo_bot.py Co-authored-by: Oleg A. <t0rr@mail.ru> * Rename `handler` -> `handlers` * Update __init__.py Co-authored-by: Oleg A. <t0rr@mail.ru>
This commit is contained in:
parent
5e7932ca20
commit
4315ecf1a2
111 changed files with 376 additions and 390 deletions
65
tests/test_handler/test_message.py
Normal file
65
tests/test_handler/test_message.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import datetime
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.filters import CommandObject
|
||||
from aiogram.handlers import MessageHandler, MessageHandlerCommandMixin
|
||||
from aiogram.types import Chat, Message, User
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class MyHandler(MessageHandler):
|
||||
async def handle(self) -> Any:
|
||||
return self.event.text
|
||||
|
||||
|
||||
class TestClassBasedMessageHandler:
|
||||
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
|
||||
|
||||
|
||||
class HandlerWithCommand(MessageHandlerCommandMixin, MessageHandler):
|
||||
async def handle(self) -> Any:
|
||||
return self.command
|
||||
|
||||
|
||||
class TestBaseMessageHandlerCommandMixin:
|
||||
def test_command_accessible(self):
|
||||
handler = HandlerWithCommand(
|
||||
Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
text="/test args",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
),
|
||||
command=CommandObject(prefix="/", command="command", args="args"),
|
||||
)
|
||||
|
||||
assert isinstance(handler.command, CommandObject)
|
||||
assert handler.command.command == "command"
|
||||
|
||||
def test_command_not_presented(self):
|
||||
handler = HandlerWithCommand(
|
||||
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"),
|
||||
)
|
||||
)
|
||||
|
||||
assert handler.command is None
|
||||
Loading…
Add table
Add a link
Reference in a new issue