mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Global filters for router (#644)
* Bump version * Added more comments * Cover registering global filters * Reformat code * Add more tests * Rework event propagation to routers mechanism. Fixed compatibility with Python 3.10 syntax (match keyword) * Fixed tests * Fixed coverage Co-authored-by: evgfilim1 <evgfilim1@yandex.ru>
This commit is contained in:
parent
a70ecb767f
commit
4f2cc75951
13 changed files with 176 additions and 31 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.dispatcher.event.bases import SkipHandler, skip
|
||||
from aiogram.dispatcher.event.bases import SkipHandler, skip, UNHANDLED
|
||||
from aiogram.dispatcher.router import Router
|
||||
from aiogram.utils.warnings import CodeHasNoEffect
|
||||
|
||||
|
|
@ -122,3 +122,17 @@ class TestRouter:
|
|||
skip()
|
||||
with pytest.raises(SkipHandler, match="KABOOM"):
|
||||
skip("KABOOM")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_global_filter_in_nested_router(self):
|
||||
r1 = Router()
|
||||
r2 = Router()
|
||||
|
||||
async def handler(evt):
|
||||
return evt
|
||||
|
||||
r1.include_router(r2)
|
||||
r1.message.filter(lambda evt: False)
|
||||
r2.message.register(handler)
|
||||
|
||||
assert await r1.propagate_event(update_type="message", event=None) is UNHANDLED
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue