From 05e6cfca62162ffa5ca7e524f08810bc4d0df42a Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Sat, 30 Oct 2021 22:56:18 -0700 Subject: [PATCH] feat(rpc): add msearch type handler Signed-off-by: Kevin Morris --- aurweb/rpc.py | 9 +++------ test/test_rpc.py | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/aurweb/rpc.py b/aurweb/rpc.py index 16985f37..56f75391 100644 --- a/aurweb/rpc.py +++ b/aurweb/rpc.py @@ -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 [] diff --git a/test/test_rpc.py b/test/test_rpc.py index 38b81226..0636c792 100644 --- a/test/test_rpc.py +++ b/test/test_rpc.py @@ -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")