[debug] ajout des routes /error/{code:str} et /exception

This commit is contained in:
Maxime Alves LIRMM@home 2021-03-12 18:59:30 +01:00
parent a3d546905c
commit 607a288e28
2 changed files with 33 additions and 0 deletions

View File

@ -153,3 +153,14 @@ def debug_routes():
logger.critical('debuglog# %s', {datetime.now().isoformat()}) logger.critical('debuglog# %s', {datetime.now().isoformat()})
return Response('') return Response('')
yield Route('/halfapi/log', debug_log) 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)

View File

@ -16,3 +16,25 @@ def test_current_user():
c = TestClient(application) c = TestClient(application)
r = c.get('/halfapi/current_user') r = c.get('/halfapi/current_user')
assert r.status_code == 200 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')