mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Forum topic in FSM (#1161)
* Base implementation * Added tests, fixed arguments priority * Use `Optional[X]` instead of `X | None` * Added changelog * Added tests
This commit is contained in:
parent
1538bc2e2d
commit
942ba0d520
10 changed files with 164 additions and 60 deletions
|
|
@ -14,7 +14,7 @@ from aiogram import Bot
|
|||
from aiogram.dispatcher.dispatcher import Dispatcher
|
||||
from aiogram.dispatcher.event.bases import UNHANDLED, SkipHandler
|
||||
from aiogram.dispatcher.router import Router
|
||||
from aiogram.methods import GetMe, GetUpdates, Request, SendMessage, TelegramMethod
|
||||
from aiogram.methods import GetMe, GetUpdates, SendMessage, TelegramMethod
|
||||
from aiogram.types import (
|
||||
CallbackQuery,
|
||||
Chat,
|
||||
|
|
@ -462,9 +462,9 @@ class TestDispatcher:
|
|||
async def my_handler(event: Any, **kwargs: Any):
|
||||
assert event == getattr(update, event_type)
|
||||
if has_chat:
|
||||
assert Chat.get_current(False)
|
||||
assert kwargs["event_chat"]
|
||||
if has_user:
|
||||
assert User.get_current(False)
|
||||
assert kwargs["event_from_user"]
|
||||
return kwargs
|
||||
|
||||
result = await router.feed_update(bot, update, test="PASS")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.dispatcher.middlewares.user_context import UserContextMiddleware
|
||||
from aiogram.types import Update
|
||||
|
||||
|
||||
async def next_handler(*args, **kwargs):
|
||||
|
|
@ -11,3 +14,13 @@ class TestUserContextMiddleware:
|
|||
async def test_unexpected_event_type(self):
|
||||
with pytest.raises(RuntimeError):
|
||||
await UserContextMiddleware()(next_handler, object(), {})
|
||||
|
||||
async def test_call(self):
|
||||
middleware = UserContextMiddleware()
|
||||
data = {}
|
||||
with patch.object(UserContextMiddleware, "resolve_event_context", return_value=[1, 2, 3]):
|
||||
await middleware(next_handler, Update(update_id=42), data)
|
||||
|
||||
assert data["event_chat"] == 1
|
||||
assert data["event_from_user"] == 2
|
||||
assert data["event_thread_id"] == 3
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue