mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(fastapi): support by
maintainer search with no keywords
In this case, package search should return orphaned packages. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
a38e126f49
commit
c28f1695ed
2 changed files with 30 additions and 3 deletions
|
@ -90,9 +90,13 @@ class PackageSearch:
|
|||
return self
|
||||
|
||||
def _search_by_maintainer(self, keywords: str) -> orm.Query:
|
||||
if keywords:
|
||||
self.query = self.query.join(
|
||||
models.User, models.User.ID == models.PackageBase.MaintainerUID
|
||||
).filter(models.User.Username == keywords)
|
||||
else:
|
||||
self.query = self.query.filter(
|
||||
models.PackageBase.MaintainerUID.is_(None))
|
||||
return self
|
||||
|
||||
def _search_by_comaintainer(self, keywords: str) -> orm.Query:
|
||||
|
|
|
@ -623,13 +623,36 @@ def test_packages_search_by_keywords(client: TestClient,
|
|||
def test_packages_search_by_maintainer(client: TestClient,
|
||||
maintainer: User,
|
||||
package: Package):
|
||||
# We should expect that searching by `package`'s maintainer
|
||||
# returns `package` in the results.
|
||||
with client as request:
|
||||
response = request.get("/packages", params={
|
||||
"SeB": "m",
|
||||
"K": maintainer.Username
|
||||
})
|
||||
assert response.status_code == int(HTTPStatus.OK)
|
||||
root = parse_root(response.text)
|
||||
rows = root.xpath('//table[@class="results"]/tbody/tr')
|
||||
assert len(rows) == 1
|
||||
|
||||
# Search again by maintainer with no keywords given.
|
||||
# This kind of search returns all orphans instead.
|
||||
# In this first case, there are no orphan packages; assert that.
|
||||
with client as request:
|
||||
response = request.get("/packages", params={"SeB": "m"})
|
||||
assert response.status_code == int(HTTPStatus.OK)
|
||||
root = parse_root(response.text)
|
||||
rows = root.xpath('//table[@class="results"]/tbody/tr')
|
||||
assert len(rows) == 0
|
||||
|
||||
# Orphan `package`.
|
||||
with db.begin():
|
||||
package.PackageBase.Maintainer = None
|
||||
|
||||
# This time, we should get `package` returned, since it's now an orphan.
|
||||
with client as request:
|
||||
response = request.get("/packages", params={"SeB": "m"})
|
||||
assert response.status_code == int(HTTPStatus.OK)
|
||||
root = parse_root(response.text)
|
||||
rows = root.xpath('//table[@class="results"]/tbody/tr')
|
||||
assert len(rows) == 1
|
||||
|
|
Loading…
Add table
Reference in a new issue