Verified Commit 73f0bddf authored by Leonidas Spyropoulos's avatar Leonidas Spyropoulos
Browse files

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's avatarLeonidas Spyropoulos <artafinde@archlinux.org>
parent c248a74f
Pipeline #37898 passed with stages
in 3 minutes and 9 seconds
......@@ -18,6 +18,13 @@ from aurweb.requests.util import get_pkgreq_by_id
from aurweb.scripts import notify
from aurweb.templates import make_context, render_template
FILTER_PARAMS = {
"filter_pending",
"filter_closed",
"filter_accepted",
"filter_rejected",
}
router = APIRouter()
......@@ -36,7 +43,7 @@ async def requests(
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
O, PP = util.sanitize_params(O, PP)
......@@ -89,7 +96,6 @@ async def requests(
.offset(O)
.all()
)
return render_template(request, "requests.html", context)
......
......@@ -734,6 +734,52 @@ def test_requests(
rows = root.xpath('//table[@class="results"]/tbody/tr')
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.
with client as request:
resp = request.get(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment