diff --git a/CHANGES/1117.feature.rst b/CHANGES/1117.feature.rst new file mode 100644 index 00000000..cdcf0999 --- /dev/null +++ b/CHANGES/1117.feature.rst @@ -0,0 +1 @@ +Added a method that allows you to compactly register routers \ No newline at end of file diff --git a/aiogram/dispatcher/router.py b/aiogram/dispatcher/router.py index 12f59fb1..6595c428 100644 --- a/aiogram/dispatcher/router.py +++ b/aiogram/dispatcher/router.py @@ -179,7 +179,7 @@ class Router: self._parent_router = router router.sub_routers.append(self) - def include_routers(self, *routers): + def include_routers(self, *routers) -> Router: if not routers: raise ValueError("You must provide routers") for router in routers: diff --git a/tests/test_dispatcher/test_router.py b/tests/test_dispatcher/test_router.py index 673bb46d..d1d423ae 100644 --- a/tests/test_dispatcher/test_router.py +++ b/tests/test_dispatcher/test_router.py @@ -33,6 +33,18 @@ class TestRouter: assert router3.parent_router is router2 assert router3.sub_routers == [] + def test_including_many_routers(self): + router = Router() + router1 = Router() + router2 = Router() + + with pytest.raises(ValueError, match="You must provide routers"): + router.include_routers() + + router.include_routers(router1, router2) + + assert router.sub_routers == [router1, router2] + def test_include_router_by_string_bad_type(self): router = Router() with pytest.raises(ValueError, match=r"router should be instance of Router"):