mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
fix: ensure middleware data is passed to scene entry handler (#1674)
Some checks failed
Tests / tests (macos-latest, 3.10) (push) Has been cancelled
Tests / tests (macos-latest, 3.11) (push) Has been cancelled
Tests / tests (macos-latest, 3.12) (push) Has been cancelled
Tests / tests (macos-latest, 3.13) (push) Has been cancelled
Tests / tests (macos-latest, 3.9) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.10) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.12) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.13) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.9) (push) Has been cancelled
Tests / tests (windows-latest, 3.10) (push) Has been cancelled
Tests / tests (windows-latest, 3.11) (push) Has been cancelled
Tests / tests (windows-latest, 3.12) (push) Has been cancelled
Tests / tests (windows-latest, 3.13) (push) Has been cancelled
Tests / tests (windows-latest, 3.9) (push) Has been cancelled
Tests / pypy-tests (macos-latest, pypy3.10) (push) Has been cancelled
Tests / pypy-tests (macos-latest, pypy3.9) (push) Has been cancelled
Tests / pypy-tests (ubuntu-latest, pypy3.10) (push) Has been cancelled
Tests / pypy-tests (ubuntu-latest, pypy3.9) (push) Has been cancelled
Some checks failed
Tests / tests (macos-latest, 3.10) (push) Has been cancelled
Tests / tests (macos-latest, 3.11) (push) Has been cancelled
Tests / tests (macos-latest, 3.12) (push) Has been cancelled
Tests / tests (macos-latest, 3.13) (push) Has been cancelled
Tests / tests (macos-latest, 3.9) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.10) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.12) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.13) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.9) (push) Has been cancelled
Tests / tests (windows-latest, 3.10) (push) Has been cancelled
Tests / tests (windows-latest, 3.11) (push) Has been cancelled
Tests / tests (windows-latest, 3.12) (push) Has been cancelled
Tests / tests (windows-latest, 3.13) (push) Has been cancelled
Tests / tests (windows-latest, 3.9) (push) Has been cancelled
Tests / pypy-tests (macos-latest, pypy3.10) (push) Has been cancelled
Tests / pypy-tests (macos-latest, pypy3.9) (push) Has been cancelled
Tests / pypy-tests (ubuntu-latest, pypy3.10) (push) Has been cancelled
Tests / pypy-tests (ubuntu-latest, pypy3.9) (push) Has been cancelled
* fix: ensure middleware data is passed to scene entry handler * Add documentation for entering scenes with various methods * Update changelog
This commit is contained in:
parent
a4256950e4
commit
eb84458ff5
5 changed files with 191 additions and 3 deletions
|
|
@ -685,6 +685,44 @@ class TestScene:
|
|||
|
||||
scenes.enter.assert_called_once_with(MyScene, **kwargs)
|
||||
|
||||
async def test_scene_as_handler_enter_with_middleware_data(self):
|
||||
"""Test that middleware data is correctly passed to the scene when using as_handler()."""
|
||||
|
||||
class MyScene(Scene):
|
||||
@on.message.enter()
|
||||
def test_handler(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
event = AsyncMock()
|
||||
|
||||
scenes = ScenesManager(
|
||||
registry=SceneRegistry(Router()),
|
||||
update_type="message",
|
||||
event=event,
|
||||
state=FSMContext(
|
||||
storage=MemoryStorage(), key=StorageKey(bot_id=42, chat_id=-42, user_id=42)
|
||||
),
|
||||
data={},
|
||||
)
|
||||
scenes.enter = AsyncMock()
|
||||
|
||||
# Kwargs passed to as_handler
|
||||
handler_kwargs = {"handler_kwarg": "handler_value", "mixed_kwarg": "handler_value"}
|
||||
handler = MyScene.as_handler(**handler_kwargs)
|
||||
|
||||
# Middleware data that would be passed to the handler
|
||||
middleware_data = {
|
||||
"middleware_data": "middleware_value",
|
||||
"mixed_kwarg": "middleware_value",
|
||||
}
|
||||
|
||||
# Call the handler with middleware data
|
||||
await handler(event, scenes, **middleware_data)
|
||||
|
||||
# Verify that both handler kwargs and middleware data are passed to scenes.enter
|
||||
expected_kwargs = {**handler_kwargs, **middleware_data}
|
||||
scenes.enter.assert_called_once_with(MyScene, **expected_kwargs)
|
||||
|
||||
|
||||
class TestSceneWizard:
|
||||
async def test_scene_wizard_enter_with_reset_data_on_enter(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue