From fa7bbb62e2f7c1b656aea84a6b7bfd636fca27dd Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 14 Dec 2022 14:59:11 +0100 Subject: [PATCH] correct error codes in tests --- lnbits/app.py | 5 +++-- tests/core/views/test_generic.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lnbits/app.py b/lnbits/app.py index b688ec8d..6efd82fe 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -184,7 +184,7 @@ def register_exception_handlers(app: FastAPI): ) return JSONResponse( - status_code=HTTPStatus.NO_CONTENT, + status_code=HTTPStatus.INTERNAL_SERVER_ERROR, content={"detail": exc_str}, ) @@ -192,6 +192,7 @@ def register_exception_handlers(app: FastAPI): async def validation_exception_handler( request: Request, exc: RequestValidationError ): + logger.error(str(exc)) # Only the browser sends "text/html" request # not fail proof, but everything else get's a JSON response @@ -206,7 +207,7 @@ def register_exception_handlers(app: FastAPI): ) return JSONResponse( - status_code=HTTPStatus.NO_CONTENT, + status_code=HTTPStatus.BAD_REQUEST, content={"detail": exc.errors()}, ) diff --git a/tests/core/views/test_generic.py b/tests/core/views/test_generic.py index 4300b78b..e8fc6fcc 100644 --- a/tests/core/views/test_generic.py +++ b/tests/core/views/test_generic.py @@ -46,11 +46,11 @@ async def test_get_wallet_no_redirect(client): i += 1 -# check GET /wallet: wrong user, expect 204 +# check GET /wallet: wrong user, expect 400 @pytest.mark.asyncio async def test_get_wallet_with_nonexistent_user(client): response = await client.get("wallet", params={"usr": "1"}) - assert response.status_code == 204, ( + assert response.status_code == 400, ( str(response.url) + " " + str(response.status_code) ) @@ -91,11 +91,11 @@ async def test_get_wallet_with_user_and_wallet(client, to_user, to_wallet): ) -# check GET /wallet: wrong wallet and user, expect 204 +# check GET /wallet: wrong wallet and user, expect 400 @pytest.mark.asyncio async def test_get_wallet_with_user_and_wrong_wallet(client, to_user): response = await client.get("wallet", params={"usr": to_user.id, "wal": "1"}) - assert response.status_code == 204, ( + assert response.status_code == 400, ( str(response.url) + " " + str(response.status_code) ) @@ -109,20 +109,20 @@ async def test_get_extensions(client, to_user): ) -# check GET /extensions: extensions list wrong user, expect 204 +# check GET /extensions: extensions list wrong user, expect 400 @pytest.mark.asyncio async def test_get_extensions_wrong_user(client, to_user): response = await client.get("extensions", params={"usr": "1"}) - assert response.status_code == 204, ( + assert response.status_code == 400, ( str(response.url) + " " + str(response.status_code) ) -# check GET /extensions: no user given, expect code 204 no content +# check GET /extensions: no user given, expect code 400 bad request @pytest.mark.asyncio async def test_get_extensions_no_user(client): response = await client.get("extensions") - assert response.status_code == 204, ( # no content + assert response.status_code == 400, ( # bad request str(response.url) + " " + str(response.status_code) )