feat(FastAPI): add /pkgbase/{name}/adopt (post)

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-10-07 22:01:04 -07:00
parent 72d6016da4
commit 305d077973
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
3 changed files with 65 additions and 4 deletions

View file

@ -1849,6 +1849,39 @@ def test_pkgbase_disown(client: TestClient, user: User, maintainer: User,
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
def test_pkgbase_adopt(client: TestClient, user: User, tu_user: User,
maintainer: User, package: Package):
# Unset the maintainer as if package is orphaned.
with db.begin():
package.PackageBase.Maintainer = None
pkgbasename = package.PackageBase.Name
cookies = {"AURSID": maintainer.login(Request(), "testPassword")}
endpoint = f"/pkgbase/{pkgbasename}/adopt"
# Adopt the package base.
with client as request:
resp = request.post(endpoint, cookies=cookies, allow_redirects=False)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
assert package.PackageBase.Maintainer == maintainer
# Try to adopt it when it already has a maintainer; nothing changes.
user_cookies = {"AURSID": user.login(Request(), "testPassword")}
with client as request:
resp = request.post(endpoint, cookies=user_cookies,
allow_redirects=False)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
assert package.PackageBase.Maintainer == maintainer
# Steal the package as a TU.
tu_cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
with client as request:
resp = request.post(endpoint, cookies=tu_cookies,
allow_redirects=False)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
assert package.PackageBase.Maintainer == tu_user
def test_pkgbase_delete_unauthorized(client: TestClient, user: User,
package: Package):
pkgbase = package.PackageBase