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

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