Add possibility to include router via string

This commit is contained in:
Alex Root Junior 2019-12-12 00:28:37 +02:00
parent b943ea2207
commit dadedc80a9
6 changed files with 86 additions and 3 deletions

View file

@ -20,6 +20,8 @@ from aiogram.api.types import (
from aiogram.dispatcher.event.observer import SkipHandler
from aiogram.dispatcher.router import Router
importable_router = Router()
class TestRouter:
def test_including_routers(self):
@ -50,6 +52,15 @@ class TestRouter:
assert router3.parent_router is router2
assert router3.sub_routers == []
def test_include_router_by_string(self):
router = Router()
router.include_router("tests.test_dispatcher.test_router:importable_router")
def test_include_router_by_string_bad_type(self):
router = Router()
with pytest.raises(ValueError, match=r"router should be instance of Router"):
router.include_router("tests.test_dispatcher.test_router:TestRouter")
def test_observers_config(self):
router = Router()
assert router.update_handler.handlers