feat(rpc): add msearch type handler

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-10-30 22:56:18 -07:00
parent 9fef8b0611
commit 05e6cfca62
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 32 additions and 15 deletions

View file

@ -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 []

View file

@ -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")