[debug] ajout des routes /error/{code:str} et /exception
This commit is contained in:
parent
a3d546905c
commit
607a288e28
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue