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

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

View file

@ -1080,6 +1080,7 @@ def test_pkgbase_comments(client: TestClient, maintainer: User, user: User,
def test_pkgbase_comment_delete(client: TestClient,
maintainer: User,
user: User,
package: Package,
comment: PackageComment):
@ -1094,6 +1095,18 @@ def test_pkgbase_comment_delete(client: TestClient,
expected = f"/pkgbase/{pkgbasename}"
assert resp.headers.get("location") == expected
# Test the unauthorized case of comment undeletion.
maint_cookies = {"AURSID": maintainer.login(Request(), "testPassword")}
endpoint = f"/pkgbase/{pkgbasename}/comments/{comment.ID}/undelete"
with client as request:
resp = request.post(endpoint, cookies=maint_cookies)
assert resp.status_code == int(HTTPStatus.UNAUTHORIZED)
# And move on to undeleting it.
with client as request:
resp = request.post(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
def test_pkgbase_comment_delete_unauthorized(client: TestClient,
maintainer: User,
@ -1118,3 +1131,15 @@ def test_pkgbase_comment_delete_not_found(client: TestClient,
with client as request:
resp = request.post(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.NOT_FOUND)
def test_pkgbase_comment_undelete_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}/undelete"
with client as request:
resp = request.post(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.NOT_FOUND)