mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix: sqlalchemy sessions per request
Best practice for web-apps is to have a session per web request. Instead of having a per worker-thread, we add a middleware that generates a unique ID per request, utilizing scoped_sessions scopefunc (custom function for defining a session scope) in combination with a ContextVar. With this we create a new session per request. Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
parent
d7ecede2eb
commit
3558c6ae5c
8 changed files with 94 additions and 19 deletions
|
@ -1531,6 +1531,7 @@ def test_packages_post_disown_as_maintainer(
|
|||
errors = get_errors(resp.text)
|
||||
expected = "You did not select any packages to disown."
|
||||
assert errors[0].text.strip() == expected
|
||||
db.refresh(package)
|
||||
assert package.PackageBase.Maintainer is not None
|
||||
|
||||
# Try to disown `package` without giving the confirm argument.
|
||||
|
@ -1555,6 +1556,7 @@ def test_packages_post_disown_as_maintainer(
|
|||
data={"action": "disown", "IDs": [package.ID], "confirm": True},
|
||||
)
|
||||
assert resp.status_code == int(HTTPStatus.BAD_REQUEST)
|
||||
db.refresh(package)
|
||||
assert package.PackageBase.Maintainer is not None
|
||||
errors = get_errors(resp.text)
|
||||
expected = "You are not allowed to disown one of the packages you selected."
|
||||
|
@ -1568,6 +1570,7 @@ def test_packages_post_disown_as_maintainer(
|
|||
data={"action": "disown", "IDs": [package.ID], "confirm": True},
|
||||
)
|
||||
|
||||
db.get_session().expire_all()
|
||||
assert package.PackageBase.Maintainer is None
|
||||
successes = get_successes(resp.text)
|
||||
expected = "The selected packages have been disowned."
|
||||
|
@ -1652,6 +1655,7 @@ def test_packages_post_delete(
|
|||
|
||||
# Whoo. Now, let's finally make a valid request as `pm_user`
|
||||
# to delete `package`.
|
||||
pkgname = package.PackageBase.Name
|
||||
with client as request:
|
||||
request.cookies = pm_cookies
|
||||
resp = request.post(
|
||||
|
@ -1664,7 +1668,7 @@ def test_packages_post_delete(
|
|||
assert successes[0].text.strip() == expected
|
||||
|
||||
# Expect that the package deletion was logged.
|
||||
pkgbases = [package.PackageBase.Name]
|
||||
pkgbases = [pkgname]
|
||||
expected = (
|
||||
f"Privileged user '{pm_user.Username}' deleted the "
|
||||
f"following package bases: {str(pkgbases)}."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue