diff --git a/halfapi/lib/routes.py b/halfapi/lib/routes.py index cc81901..6cfcb09 100644 --- a/halfapi/lib/routes.py +++ b/halfapi/lib/routes.py @@ -153,3 +153,14 @@ def debug_routes(): logger.critical('debuglog# %s', {datetime.now().isoformat()}) return Response('') yield Route('/halfapi/log', debug_log) + + async def error_code(request: Request, *args, **kwargs): + code = request.path_params.get('code') + raise HTTPException(code) + + yield Route('/halfapi/error/{code:int}', error_code) + + async def exception(request: Request, *args, **kwargs): + raise Exception('Test exception') + + yield Route('/halfapi/exception', exception) diff --git a/tests/test_debug_routes.py b/tests/test_debug_routes.py index c51f124..41605b3 100644 --- a/tests/test_debug_routes.py +++ b/tests/test_debug_routes.py @@ -16,3 +16,25 @@ def test_current_user(): c = TestClient(application) r = c.get('/halfapi/current_user') assert r.status_code == 200 + +def test_log(): + c = TestClient(application) + r = c.get('/halfapi/log') + assert r.status_code == 200 + +def test_error(): + c = TestClient(application) + r = c.get('/halfapi/error/400') + assert r.status_code == 400 + r = c.get('/halfapi/error/404') + assert r.status_code == 404 + r = c.get('/halfapi/error/500') + assert r.status_code == 500 + +def test_exception(): + c = TestClient(application) + try: + r = c.get('/halfapi/exception') + assert r.status_code == 500 + except Exception: + print('exception')