mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix: handle default requests when using pages
The default page shows the pending requests which were working OK if one used the Filters button. This fixes the case when someone submits by using the pager (Next, Last etc). Closes: #405 Signed-off-by: Leonidas Spyropoulos <artafinde@archlinux.org>
This commit is contained in:
parent
c248a74f80
commit
73f0bddf0b
2 changed files with 54 additions and 2 deletions
|
@ -18,6 +18,13 @@ from aurweb.requests.util import get_pkgreq_by_id
|
||||||
from aurweb.scripts import notify
|
from aurweb.scripts import notify
|
||||||
from aurweb.templates import make_context, render_template
|
from aurweb.templates import make_context, render_template
|
||||||
|
|
||||||
|
FILTER_PARAMS = {
|
||||||
|
"filter_pending",
|
||||||
|
"filter_closed",
|
||||||
|
"filter_accepted",
|
||||||
|
"filter_rejected",
|
||||||
|
}
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +43,7 @@ async def requests(
|
||||||
|
|
||||||
context["q"] = dict(request.query_params)
|
context["q"] = dict(request.query_params)
|
||||||
|
|
||||||
if len(dict(request.query_params)) == 0:
|
if not dict(request.query_params).keys() & FILTER_PARAMS:
|
||||||
filter_pending = True
|
filter_pending = True
|
||||||
|
|
||||||
O, PP = util.sanitize_params(O, PP)
|
O, PP = util.sanitize_params(O, PP)
|
||||||
|
@ -89,7 +96,6 @@ async def requests(
|
||||||
.offset(O)
|
.offset(O)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
return render_template(request, "requests.html", context)
|
return render_template(request, "requests.html", context)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -734,6 +734,52 @@ def test_requests(
|
||||||
rows = root.xpath('//table[@class="results"]/tbody/tr')
|
rows = root.xpath('//table[@class="results"]/tbody/tr')
|
||||||
assert len(rows) == defaults.PP
|
assert len(rows) == defaults.PP
|
||||||
|
|
||||||
|
# Request page 2 of the requests page.
|
||||||
|
with client as request:
|
||||||
|
resp = request.get("/requests", params={"O": 50}, cookies=cookies) # Page 2
|
||||||
|
assert resp.status_code == int(HTTPStatus.OK)
|
||||||
|
|
||||||
|
assert "‹ Previous" in resp.text
|
||||||
|
assert "« First" in resp.text
|
||||||
|
|
||||||
|
root = parse_root(resp.text)
|
||||||
|
rows = root.xpath('//table[@class="results"]/tbody/tr')
|
||||||
|
assert len(rows) == 5 # There are five records left on the second page.
|
||||||
|
|
||||||
|
|
||||||
|
def test_requests_with_filters(
|
||||||
|
client: TestClient,
|
||||||
|
tu_user: User,
|
||||||
|
packages: list[Package],
|
||||||
|
requests: list[PackageRequest],
|
||||||
|
):
|
||||||
|
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||||
|
with client as request:
|
||||||
|
resp = request.get(
|
||||||
|
"/requests",
|
||||||
|
params={
|
||||||
|
# Pass in url query parameters O, SeB and SB to exercise
|
||||||
|
# their paths inside of the pager_nav used in this request.
|
||||||
|
"O": 0, # Page 1
|
||||||
|
"SeB": "nd",
|
||||||
|
"SB": "n",
|
||||||
|
"filter_pending": True,
|
||||||
|
"filter_closed": True,
|
||||||
|
"filter_accepted": True,
|
||||||
|
"filter_rejected": True,
|
||||||
|
},
|
||||||
|
cookies=cookies,
|
||||||
|
)
|
||||||
|
assert resp.status_code == int(HTTPStatus.OK)
|
||||||
|
|
||||||
|
assert "Next ›" in resp.text
|
||||||
|
assert "Last »" in resp.text
|
||||||
|
|
||||||
|
root = parse_root(resp.text)
|
||||||
|
# We have 55 requests, our defaults.PP is 50, so expect we have 50 rows.
|
||||||
|
rows = root.xpath('//table[@class="results"]/tbody/tr')
|
||||||
|
assert len(rows) == defaults.PP
|
||||||
|
|
||||||
# Request page 2 of the requests page.
|
# Request page 2 of the requests page.
|
||||||
with client as request:
|
with client as request:
|
||||||
resp = request.get(
|
resp = request.get(
|
||||||
|
|
Loading…
Add table
Reference in a new issue