Verified Commit bcd808dd authored by Mario Oenning's avatar Mario Oenning
Browse files

feat(rpc): add "by" parameter - comaintainers



Add "by" parameter: comaintainers

Signed-off-by: Mario Oenning's avatarmoson-mo <mo-son@mailbox.org>
parent efd20ed2
Pipeline #39772 passed with stages
in 3 minutes and 8 seconds
......@@ -269,7 +269,7 @@ class RPCSearch(PackageSearch):
sanitization done for the PackageSearch `by` argument.
"""
keys_removed = ("b", "N", "B", "c", "M")
keys_removed = ("b", "N", "B", "M")
def __init__(self) -> "RPCSearch":
super().__init__()
......
......@@ -89,6 +89,7 @@ class RPC:
"groups",
"submitter",
"keywords",
"comaintainers",
}
# A mapping of by aliases.
......@@ -98,6 +99,7 @@ class RPC:
"maintainer": "m",
"submitter": "s",
"keywords": "k",
"comaintainers": "c",
}
def __init__(self, version: int = 0, type: str = None) -> "RPC":
......
......@@ -17,6 +17,7 @@ from aurweb.models.group import Group
from aurweb.models.license import License
from aurweb.models.package import Package
from aurweb.models.package_base import PackageBase
from aurweb.models.package_comaintainer import PackageComaintainer
from aurweb.models.package_dependency import PackageDependency
from aurweb.models.package_group import PackageGroup
from aurweb.models.package_keyword import PackageKeyword
......@@ -149,7 +150,7 @@ def packages(user: User, user2: User, user3: User) -> list[Package]:
output.append(pkg)
# Setup a few more related records on the first package:
# a license, group, some keywords and some votes.
# a license, group, some keywords, comaintainer and some votes.
with db.begin():
lic = db.create(License, Name="GPL")
db.create(PackageLicense, Package=output[0], License=lic)
......@@ -157,6 +158,13 @@ def packages(user: User, user2: User, user3: User) -> list[Package]:
grp = db.create(Group, Name="testgroup")
db.create(PackageGroup, Package=output[0], Group=grp)
db.create(
PackageComaintainer,
PackageBase=output[0].PackageBase,
User=user2,
Priority=1,
)
for keyword in ["big-chungus", "smol-chungus", "sizeable-chungus"]:
db.create(
PackageKeyword, PackageBase=output[0].PackageBase, Keyword=keyword
......@@ -957,6 +965,27 @@ def test_rpc_search_keywords(client: TestClient, packages: list[Package]):
assert data.get("resultcount") == 0
def test_rpc_search_comaintainers(
client: TestClient, user2: User, packages: list[Package]
):
params = {"v": 5, "type": "search", "by": "comaintainers", "arg": user2.Username}
with client as request:
response = request.get("/rpc", params=params)
data = response.json()
# should get 1 package
assert data.get("resultcount") == 1
names = list(sorted(r.get("Name") for r in data.get("results")))
expected_results = ["big-chungus"]
assert names == expected_results
# non-existent search
params["arg"] = "blah-blah"
response = request.get("/rpc", params=params)
data = response.json()
assert data.get("resultcount") == 0
def test_rpc_incorrect_by(client: TestClient):
params = {"v": 5, "type": "search", "by": "fake", "arg": "big"}
with client as request:
......
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