Add 4xx and 5xx http-code exception wrappers

This commit is contained in:
2025-07-16 04:15:22 +03:00
parent 751748f82a
commit 73da386003
6 changed files with 406 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
import pytest
from src.turbosloth.router import Router
from src.turbosloth.exceptions import NotFoundException, MethodNotAllowedException
def test_router_root_handler():
@@ -46,7 +47,10 @@ def test_router_match():
r = Router()
r.add('GET', 'asdf', f)
assert r.match('GET', '/asdf')
with pytest.raises(ValueError, match='404'):
with pytest.raises(NotFoundException, match='404\tNot Found: asd'):
r.match('GET', 'asd')
with pytest.raises(ValueError, match='405'):
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'):
r.match('POST', '')