Add router add_subroute method
This commit is contained in:
@@ -79,3 +79,32 @@ def test_router_pattern_match():
|
||||
|
||||
with pytest.raises(NotFoundException, match='404\tNot Found: asd'):
|
||||
r.match('GET', 'asd/basdf')
|
||||
|
||||
|
||||
def test_subroutes():
|
||||
async def f(*args):
|
||||
pass
|
||||
|
||||
async def d(*args):
|
||||
pass
|
||||
|
||||
r1 = Router()
|
||||
r2 = Router()
|
||||
|
||||
r1.add('GET', '/asdf', f)
|
||||
r2.add('GET', '/asdf/a', d)
|
||||
r1.add_subroute('', r2)
|
||||
|
||||
assert r1.match('GET', '/asdf') == ({}, f)
|
||||
assert r1.match('GET', '/asdf/a') == ({}, d)
|
||||
r1.add_subroute('/asdf', r2)
|
||||
assert r1.match('GET', '/asdf/asdf/a') == ({}, d)
|
||||
|
||||
r1.add_subroute('/asdf' * 5, r2)
|
||||
assert r1.match('GET', '/asdf' * 5 + '/asdf/a') == ({}, d)
|
||||
|
||||
with pytest.raises(NotFoundException):
|
||||
r1.match('GET', '/asdf/' * 5 + '/asdf/a')
|
||||
|
||||
r1.add_subroute('/asdf/' * 5, r2)
|
||||
assert r1.match('GET', '/asdf/' * 5 + '/asdf/a') == ({}, d)
|
||||
|
||||
Reference in New Issue
Block a user