feat(FastAPI): add /pkgbase/{name}/[un]vote (post)

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-10-05 21:32:12 -07:00
parent 0dfff2bcb2
commit 0a02df363a
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 65 additions and 0 deletions

View file

@ -1753,3 +1753,30 @@ def test_pkgbase_notify(client: TestClient, user: User, package: Package):
PackageNotification.UserID == user.ID
).first()
assert notif is None
def test_pkgbase_vote(client: TestClient, user: User, package: Package):
pkgbase = package.PackageBase
# We haven't voted yet.
vote = pkgbase.package_votes.filter(PackageVote.UsersID == user.ID).first()
assert vote is None
# Vote for the package.
cookies = {"AURSID": user.login(Request(), "testPassword")}
endpoint = f"/pkgbase/{pkgbase.Name}/vote"
with client as request:
resp = request.post(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
vote = pkgbase.package_votes.filter(PackageVote.UsersID == user.ID).first()
assert vote is not None
# Remove vote.
endpoint = f"/pkgbase/{pkgbase.Name}/unvote"
with client as request:
resp = request.post(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
vote = pkgbase.package_votes.filter(PackageVote.UsersID == user.ID).first()
assert vote is None