feat(FastAPI): add /pkgbase/{name}/comments/{id}/delete (post)

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-09-30 13:58:37 -07:00
parent d3be30744c
commit 40cd1b9029
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 66 additions and 2 deletions

View file

@ -995,7 +995,7 @@ def test_pkgbase_comments_missing_comment(client: TestClient, maintainer: User,
assert resp.status_code == int(HTTPStatus.EXPECTATION_FAILED)
def test_pkgbase_comments(client: TestClient, maintainer: User,
def test_pkgbase_comments(client: TestClient, maintainer: User, user: User,
package: Package):
cookies = {"AURSID": maintainer.login(Request(), "testPassword")}
pkgbasename = package.PackageBase.Name
@ -1077,3 +1077,44 @@ def test_pkgbase_comments(client: TestClient, maintainer: User,
data = resp.json()
assert "form" in data
def test_pkgbase_comment_delete(client: TestClient,
user: User,
package: Package,
comment: PackageComment):
# Test the unauthorized case of comment deletion.
cookies = {"AURSID": user.login(Request(), "testPassword")}
pkgbasename = package.PackageBase.Name
endpoint = f"/pkgbase/{pkgbasename}/comments/{comment.ID}/delete"
with client as request:
resp = request.post(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
expected = f"/pkgbase/{pkgbasename}"
assert resp.headers.get("location") == expected
def test_pkgbase_comment_delete_unauthorized(client: TestClient,
maintainer: User,
package: Package,
comment: PackageComment):
# Test the unauthorized case of comment deletion.
cookies = {"AURSID": maintainer.login(Request(), "testPassword")}
pkgbasename = package.PackageBase.Name
endpoint = f"/pkgbase/{pkgbasename}/comments/{comment.ID}/delete"
with client as request:
resp = request.post(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.UNAUTHORIZED)
def test_pkgbase_comment_delete_not_found(client: TestClient,
maintainer: User,
package: Package):
cookies = {"AURSID": maintainer.login(Request(), "testPassword")}
comment_id = 12345 # Non-existing comment.
pkgbasename = package.PackageBase.Name
endpoint = f"/pkgbase/{pkgbasename}/comments/{comment_id}/delete"
with client as request:
resp = request.post(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.NOT_FOUND)