From c572a97d1c0db681896ceff51c6896ad91a5cd30 Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Sat, 16 Oct 2021 17:38:33 -0700 Subject: [PATCH] fix(fastapi): EXPECTATION_FAILED -> BAD_REQUEST Usage of EXPECTATION_FAILED in these cases is totally wrong. EXPECTATION_FAILED is a failure in terms of the HTTP protocol, not user input. Change all usage of EXPECTATION_FAILED to BAD_REQUEST. Signed-off-by: Kevin Morris --- aurweb/routers/packages.py | 8 ++++---- test/test_packages_routes.py | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/aurweb/routers/packages.py b/aurweb/routers/packages.py index 61081edd..83c796db 100644 --- a/aurweb/routers/packages.py +++ b/aurweb/routers/packages.py @@ -301,7 +301,7 @@ async def pkgbase_comments_post( pkgbase = get_pkg_or_base(name, PackageBase) if not comment: - raise HTTPException(status_code=HTTPStatus.EXPECTATION_FAILED) + raise HTTPException(status_code=HTTPStatus.BAD_REQUEST) # If the provided comment is different than the record's version, # update the db record. @@ -353,7 +353,7 @@ async def pkgbase_comment_post( db_comment = get_pkgbase_comment(pkgbase, id) if not comment: - raise HTTPException(status_code=HTTPStatus.EXPECTATION_FAILED) + raise HTTPException(status_code=HTTPStatus.BAD_REQUEST) # If the provided comment is different than the record's version, # update the db record. @@ -969,7 +969,7 @@ async def pkgbase_disown_post(request: Request, name: str, context["errors"] = [("The selected packages have not been disowned, " "check the confirmation checkbox.")] return render_template(request, "packages/disown.html", context, - status_code=HTTPStatus.EXPECTATION_FAILED) + status_code=HTTPStatus.BAD_REQUEST) disown_pkgbase(pkgbase, request.user) return RedirectResponse(f"/pkgbase/{name}", @@ -1021,7 +1021,7 @@ async def pkgbase_delete_post(request: Request, name: str, context["errors"] = [("The selected packages have not been deleted, " "check the confirmation checkbox.")] return render_template(request, "packages/delete.html", context, - status_code=HTTPStatus.EXPECTATION_FAILED) + status_code=HTTPStatus.BAD_REQUEST) packages = pkgbase.packages.all() for package in packages: diff --git a/test/test_packages_routes.py b/test/test_packages_routes.py index 7eb4e532..f29c6c31 100644 --- a/test/test_packages_routes.py +++ b/test/test_packages_routes.py @@ -1048,7 +1048,7 @@ def test_pkgbase_comments_missing_comment(client: TestClient, maintainer: User, endpoint = f"/pkgbase/{package.PackageBase.Name}/comments" with client as request: resp = request.post(endpoint, cookies=cookies) - assert resp.status_code == int(HTTPStatus.EXPECTATION_FAILED) + assert resp.status_code == int(HTTPStatus.BAD_REQUEST) def test_pkgbase_comments(client: TestClient, maintainer: User, user: User, @@ -1119,10 +1119,10 @@ def test_pkgbase_comments(client: TestClient, maintainer: User, user: User, ).first() assert db_notif is not None - # Don't supply a comment; should return EXPECTATION_FAILED. + # Don't supply a comment; should return BAD_REQUEST. with client as request: fail_resp = request.post(endpoint, cookies=cookies) - assert fail_resp.status_code == int(HTTPStatus.EXPECTATION_FAILED) + assert fail_resp.status_code == int(HTTPStatus.BAD_REQUEST) # Now, test the form route, which should return form markup # via JSON. @@ -1902,7 +1902,7 @@ def test_pkgbase_disown(client: TestClient, user: User, maintainer: User, # POST as the maintainer without "confirm". with client as request: resp = request.post(endpoint, cookies=cookies) - assert resp.status_code == int(HTTPStatus.EXPECTATION_FAILED) + assert resp.status_code == int(HTTPStatus.BAD_REQUEST) # POST as the maintainer with "confirm". with client as request: @@ -1975,7 +1975,7 @@ def test_pkgbase_delete(client: TestClient, tu_user: User, package: Package): # Test that POST works and denies us because we haven't confirmed. with client as request: resp = request.post(endpoint, cookies=cookies) - assert resp.status_code == int(HTTPStatus.EXPECTATION_FAILED) + assert resp.status_code == int(HTTPStatus.BAD_REQUEST) # Test that we can actually delete the pkgbase. with client as request: