mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Merge remote-tracking branch 'origin/dev-3.x' into dev-3.x
This commit is contained in:
commit
84bc0e347b
3 changed files with 21 additions and 0 deletions
1
CHANGES/1117.feature.rst
Normal file
1
CHANGES/1117.feature.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
Added a method that allows you to compactly register routers
|
||||
|
|
@ -179,6 +179,12 @@ class Router:
|
|||
self._parent_router = router
|
||||
router.sub_routers.append(self)
|
||||
|
||||
def include_routers(self, *routers: Router) -> None:
|
||||
if not routers:
|
||||
raise ValueError("At least one router must be provided")
|
||||
for router in routers:
|
||||
self.include_router(router)
|
||||
|
||||
def include_router(self, router: Router) -> Router:
|
||||
"""
|
||||
Attach another router.
|
||||
|
|
|
|||
|
|
@ -33,6 +33,20 @@ class TestRouter:
|
|||
assert router3.parent_router is router2
|
||||
assert router3.sub_routers == []
|
||||
|
||||
def test_including_many_routers(self):
|
||||
router = Router()
|
||||
router1 = Router()
|
||||
router2 = Router()
|
||||
|
||||
router.include_routers(router1, router2)
|
||||
|
||||
assert router.sub_routers == [router1, router2]
|
||||
|
||||
def test_including_many_routers_bad_type(self):
|
||||
router = Router()
|
||||
with pytest.raises(ValueError, match="At least one router must be provided"):
|
||||
router.include_routers()
|
||||
|
||||
def test_include_router_by_string_bad_type(self):
|
||||
router = Router()
|
||||
with pytest.raises(ValueError, match=r"router should be instance of Router"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue