Files
turbosloth/tests/test_router.py
2025-07-16 02:15:13 +03:00

41 lines
991 B
Python

import pytest
from src.turbosloth.router import Router
def test_router_root_handler():
async def f(_: dict, *args):
pass
async def d(_: 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
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
def test_router_match():
async def f(_: dict, *args):
pass
async def d(_: dict, *args):
pass
r = Router()
r.add('GET', 'asdf', f)
assert r.match('GET', '/asdf')
with pytest.raises(ValueError):
r.match('GET', 'asd')