mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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 <kevr@0cost.org>
This commit is contained in:
parent
6ddf888b67
commit
c572a97d1c
2 changed files with 9 additions and 9 deletions
|
@ -301,7 +301,7 @@ async def pkgbase_comments_post(
|
||||||
pkgbase = get_pkg_or_base(name, PackageBase)
|
pkgbase = get_pkg_or_base(name, PackageBase)
|
||||||
|
|
||||||
if not comment:
|
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,
|
# If the provided comment is different than the record's version,
|
||||||
# update the db record.
|
# update the db record.
|
||||||
|
@ -353,7 +353,7 @@ async def pkgbase_comment_post(
|
||||||
db_comment = get_pkgbase_comment(pkgbase, id)
|
db_comment = get_pkgbase_comment(pkgbase, id)
|
||||||
|
|
||||||
if not comment:
|
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,
|
# If the provided comment is different than the record's version,
|
||||||
# update the db record.
|
# 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, "
|
context["errors"] = [("The selected packages have not been disowned, "
|
||||||
"check the confirmation checkbox.")]
|
"check the confirmation checkbox.")]
|
||||||
return render_template(request, "packages/disown.html", context,
|
return render_template(request, "packages/disown.html", context,
|
||||||
status_code=HTTPStatus.EXPECTATION_FAILED)
|
status_code=HTTPStatus.BAD_REQUEST)
|
||||||
|
|
||||||
disown_pkgbase(pkgbase, request.user)
|
disown_pkgbase(pkgbase, request.user)
|
||||||
return RedirectResponse(f"/pkgbase/{name}",
|
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, "
|
context["errors"] = [("The selected packages have not been deleted, "
|
||||||
"check the confirmation checkbox.")]
|
"check the confirmation checkbox.")]
|
||||||
return render_template(request, "packages/delete.html", context,
|
return render_template(request, "packages/delete.html", context,
|
||||||
status_code=HTTPStatus.EXPECTATION_FAILED)
|
status_code=HTTPStatus.BAD_REQUEST)
|
||||||
|
|
||||||
packages = pkgbase.packages.all()
|
packages = pkgbase.packages.all()
|
||||||
for package in packages:
|
for package in packages:
|
||||||
|
|
|
@ -1048,7 +1048,7 @@ def test_pkgbase_comments_missing_comment(client: TestClient, maintainer: User,
|
||||||
endpoint = f"/pkgbase/{package.PackageBase.Name}/comments"
|
endpoint = f"/pkgbase/{package.PackageBase.Name}/comments"
|
||||||
with client as request:
|
with client as request:
|
||||||
resp = request.post(endpoint, cookies=cookies)
|
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,
|
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()
|
).first()
|
||||||
assert db_notif is not None
|
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:
|
with client as request:
|
||||||
fail_resp = request.post(endpoint, cookies=cookies)
|
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
|
# Now, test the form route, which should return form markup
|
||||||
# via JSON.
|
# via JSON.
|
||||||
|
@ -1902,7 +1902,7 @@ def test_pkgbase_disown(client: TestClient, user: User, maintainer: User,
|
||||||
# POST as the maintainer without "confirm".
|
# POST as the maintainer without "confirm".
|
||||||
with client as request:
|
with client as request:
|
||||||
resp = request.post(endpoint, cookies=cookies)
|
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".
|
# POST as the maintainer with "confirm".
|
||||||
with client as request:
|
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.
|
# Test that POST works and denies us because we haven't confirmed.
|
||||||
with client as request:
|
with client as request:
|
||||||
resp = request.post(endpoint, cookies=cookies)
|
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.
|
# Test that we can actually delete the pkgbase.
|
||||||
with client as request:
|
with client as request:
|
||||||
|
|
Loading…
Add table
Reference in a new issue