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:
Alex Root Junior 2021-07-31 23:34:09 +03:00 committed by GitHub
parent a70ecb767f
commit 4f2cc75951
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 176 additions and 31 deletions

View file

@ -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