Verified Commit 05e6cfca authored by Kevin Morris's avatar Kevin Morris
Browse files

feat(rpc): add msearch type handler



Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 9fef8b06
Pipeline #12742 waiting for manual action with stages
in 6 minutes and 36 seconds
......@@ -101,12 +101,6 @@ class RPC:
if self.type not in RPC.EXPOSED_TYPES:
raise RPCError("Incorrect request type specified.")
try:
getattr(self, f"_handle_{self.type.replace('-', '_')}_type")
except AttributeError:
raise RPCError(
f"Request type '{self.type}' is not yet implemented.")
def _enforce_args(self, args: List[str]):
if not args:
raise RPCError("No request type/data specified.")
......@@ -211,6 +205,9 @@ class RPC:
results = search.results().limit(max_results)
return [self._get_json_data(pkg) for pkg in results]
def _handle_msearch_type(self, args: List[str] = [], **kwargs):
return self._handle_search_type(by="m", args=args)
def _handle_suggest_type(self, args: List[str] = [], **kwargs):
if not args:
return []
......
......@@ -483,15 +483,6 @@ def test_rpc_suggest():
assert data == []
def test_rpc_unimplemented_types():
unimplemented = ["msearch"]
for type in unimplemented:
response = make_request(f"/rpc?v=5&type={type}&arg=big")
data = response.json()
expected = f"Request type '{type}' is not yet implemented."
assert data.get("error") == expected
def mock_config_getint(section: str, key: str):
if key == "request_limit":
return 4
......@@ -551,6 +542,35 @@ def test_rpc_search():
assert response.json().get("error") == "No request type/data specified."
def test_rpc_msearch():
response = make_request("/rpc?v=5&type=msearch&arg=user1")
data = response.json()
# user1 maintains 4 packages; assert that we got them all.
assert data.get("resultcount") == 4
names = list(sorted(r.get("Name") for r in data.get("results")))
expected_results = list(sorted([
"big-chungus",
"chungy-chungus",
"gluggly-chungus",
"other-pkg"
]))
assert names == expected_results
# Search for a non-existent maintainer, giving us zero packages.
response = make_request("/rpc?v=5&type=msearch&arg=blah-blah")
data = response.json()
assert data.get("resultcount") == 0
# A missing arg still succeeds, but it returns all orphans.
# Just verify that we receive no error and the orphaned result.
response = make_request("/rpc?v=5&type=msearch")
data = response.json()
assert data.get("resultcount") == 1
result = data.get("results")[0]
assert result.get("Name") == "woogly-chungus"
def test_rpc_search_depends():
response = make_request(
"/rpc?v=5&type=search&by=depends&arg=chungus-depends")
......
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