Allow router to raise MethodNotAllowed
This commit is contained in:
@@ -10,20 +10,30 @@ def test_router_root_handler():
|
||||
async def d(_: dict, *args):
|
||||
pass
|
||||
|
||||
async def a(_: dict, *args):
|
||||
pass
|
||||
|
||||
r = Router()
|
||||
r.add('GET', '/', f)
|
||||
r.add('GET', '', f)
|
||||
assert len(r._routes.keys()) == 1
|
||||
assert len(r._routes['GET'].static_subroutes.keys()) == 0
|
||||
assert r._routes['GET'].handler is not None
|
||||
assert r._routes['GET'].handler == f
|
||||
assert len(r._root.static_subroutes) == 0
|
||||
assert len(r._root.handler) == 1
|
||||
assert r._root.handler['GET'] == f
|
||||
|
||||
r.add('POST', '/', a)
|
||||
assert len(r._root.static_subroutes) == 0
|
||||
assert len(r._root.handler) == 2
|
||||
assert r._root.handler['GET'] == f
|
||||
assert r._root.handler['POST'] == a
|
||||
|
||||
r.add('GET', '/asdf', d)
|
||||
assert len(r._routes.keys()) == 1
|
||||
assert len(r._routes['GET'].static_subroutes.keys()) == 1
|
||||
assert r._routes['GET'].handler is not None
|
||||
assert r._routes['GET'].handler == f
|
||||
assert r._routes['GET'].static_subroutes['asdf'].handler == d
|
||||
assert len(r._root.static_subroutes) == 1
|
||||
assert len(r._root.handler) == 2
|
||||
assert r._root.handler['GET'] == f
|
||||
assert r._root.handler['POST'] == a
|
||||
assert len(r._root.static_subroutes['asdf'].static_subroutes) == 0
|
||||
assert len(r._root.static_subroutes['asdf'].handler) == 1
|
||||
assert r._root.static_subroutes['asdf'].handler['GET'] == d
|
||||
|
||||
|
||||
def test_router_match():
|
||||
@@ -36,5 +46,7 @@ def test_router_match():
|
||||
r = Router()
|
||||
r.add('GET', 'asdf', f)
|
||||
assert r.match('GET', '/asdf')
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(ValueError, match='404'):
|
||||
r.match('GET', 'asd')
|
||||
with pytest.raises(ValueError, match='405'):
|
||||
r.match('POST', 'asdf')
|
||||
|
||||
Reference in New Issue
Block a user