Add pattern-substitutive by regexp path matching
This commit is contained in:
@@ -5,13 +5,13 @@ from src.turbosloth.router import Router
|
||||
|
||||
|
||||
def test_router_root_handler():
|
||||
async def f(_: dict, *args):
|
||||
async def f(*args):
|
||||
pass
|
||||
|
||||
async def d(_: dict, *args):
|
||||
async def d(*args):
|
||||
pass
|
||||
|
||||
async def a(_: dict, *args):
|
||||
async def a(*args):
|
||||
pass
|
||||
|
||||
r = Router()
|
||||
@@ -38,10 +38,10 @@ def test_router_root_handler():
|
||||
|
||||
|
||||
def test_router_match():
|
||||
async def f(_: dict, *args):
|
||||
async def f(*args):
|
||||
pass
|
||||
|
||||
async def d(_: dict, *args):
|
||||
async def d(*args):
|
||||
pass
|
||||
|
||||
r = Router()
|
||||
@@ -52,5 +52,30 @@ def test_router_match():
|
||||
with pytest.raises(MethodNotAllowedException, match=f'405\tMethod Not Allowed: POST /asdf, allowed: GET'):
|
||||
r.match('POST', 'asdf')
|
||||
|
||||
with pytest.raises(MethodNotAllowedException, match=f'405\tMethod Not Allowed: POST /, allowed: none'):
|
||||
with pytest.raises(NotFoundException, match=f'404\tNot Found'):
|
||||
r.match('POST', '')
|
||||
|
||||
|
||||
def test_router_pattern_match():
|
||||
async def f(*args):
|
||||
pass
|
||||
|
||||
r = Router()
|
||||
r.add('GET', '/{some}/asdf', f)
|
||||
r.add('GET', '/{some}/b{some1}c', f)
|
||||
|
||||
assert r.match('GET', '/1234/asdf')
|
||||
assert r.match('GET', '/ /asdf')
|
||||
assert r.match('GET', '/ /basdfc')
|
||||
|
||||
with pytest.raises(NotFoundException, match='404\tNot Found: asd'):
|
||||
r.match('GET', 'asd')
|
||||
|
||||
with pytest.raises(NotFoundException, match='404\tNot Found: asd'):
|
||||
r.match('GET', 'asd/')
|
||||
|
||||
with pytest.raises(NotFoundException, match='404\tNot Found: asd'):
|
||||
r.match('GET', 'asd/b')
|
||||
|
||||
with pytest.raises(NotFoundException, match='404\tNot Found: asd'):
|
||||
r.match('GET', 'asd/basdf')
|
||||
|
||||
Reference in New Issue
Block a user