Verified Commit 5484e68b authored by Mario Oenning's avatar Mario Oenning
Browse files

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



Add "by" parameter: submitter

Signed-off-by: Mario Oenning's avatarmoson-mo <mo-son@mailbox.org>
parent 0583f30a
......@@ -269,7 +269,7 @@ class RPCSearch(PackageSearch):
sanitization done for the PackageSearch `by` argument.
"""
keys_removed = ("b", "N", "B", "k", "c", "M", "s")
keys_removed = ("b", "N", "B", "k", "c", "M")
def __init__(self) -> "RPCSearch":
super().__init__()
......
......@@ -87,10 +87,11 @@ class RPC:
"conflicts",
"replaces",
"groups",
"submitter",
}
# A mapping of by aliases.
BY_ALIASES = {"name-desc": "nd", "name": "n", "maintainer": "m"}
BY_ALIASES = {"name-desc": "nd", "name": "n", "maintainer": "m", "submitter": "s"}
def __init__(self, version: int = 0, type: str = None) -> "RPC":
self.version = version
......
......@@ -81,7 +81,11 @@ def packages(user: User, user2: User, user3: User) -> list[Package]:
# Create package records used in our tests.
with db.begin():
pkgbase = db.create(
PackageBase, Name="big-chungus", Maintainer=user, Packager=user
PackageBase,
Name="big-chungus",
Maintainer=user,
Packager=user,
Submitter=user2,
)
pkg = db.create(
Package,
......@@ -93,7 +97,11 @@ def packages(user: User, user2: User, user3: User) -> list[Package]:
output.append(pkg)
pkgbase = db.create(
PackageBase, Name="chungy-chungus", Maintainer=user, Packager=user
PackageBase,
Name="chungy-chungus",
Maintainer=user,
Packager=user,
Submitter=user2,
)
pkg = db.create(
Package,
......@@ -911,6 +919,25 @@ def test_rpc_search_groups(
assert result.get("Name") == packages[0].Name
def test_rpc_search_submitter(client: TestClient, user2: User, packages: list[Package]):
params = {"v": 5, "type": "search", "by": "submitter", "arg": user2.Username}
with client as request:
response = request.get("/rpc", params=params)
data = response.json()
# user2 submitted 2 packages
assert data.get("resultcount") == 2
names = list(sorted(r.get("Name") for r in data.get("results")))
expected_results = ["big-chungus", "chungy-chungus"]
assert names == expected_results
# Search for a non-existent submitter, giving us zero packages.
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