feat(rpc): add GET /rpc/v5/suggest/{arg} openapi route

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-09-12 06:49:54 -07:00
parent 8e8b746a5b
commit 17f2c05fd3
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 28 additions and 0 deletions

View file

@ -281,3 +281,15 @@ async def rpc_openapi_search_post(
arg, arg,
[], [],
) )
@router.get("/rpc/v{version}/suggest/{arg}")
async def rpc_openapi_suggest(request: Request, version: int, arg: str):
return await rpc_request(
request,
version,
"suggest",
defaults.RPC_SEARCH_BY,
arg,
[],
)

View file

@ -1040,3 +1040,19 @@ def test_rpc_openapi_search_post_bad_request(client: TestClient):
data = resp.json() data = resp.json()
expected = "the 'arg' parameter must be of string type" expected = "the 'arg' parameter must be of string type"
assert data.get("error") == expected assert data.get("error") == expected
def test_rpc_openapi_suggest(client: TestClient, packages: list[Package]):
suggestions = {
"big": ["big-chungus"],
"chungy": ["chungy-chungus"],
}
for term, expected in suggestions.items():
with client as request:
endp = f"/rpc/v5/suggest/{term}"
resp = request.get(endp)
assert resp.status_code == HTTPStatus.OK
data = resp.json()
assert data == expected