Verified Commit 9d6dbaf0 authored by Kevin Morris's avatar Kevin Morris
Browse files

feat(rpc): add suggest type handler



Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent a38e126f
......@@ -175,6 +175,14 @@ class RPC:
models.Package.Name.in_(args))
return [self._get_json_data(pkg) for pkg in packages]
def _handle_suggest_type(self, args: List[str] = []):
arg = args[0]
packages = db.query(models.Package).join(models.PackageBase).filter(
and_(models.PackageBase.PackagerUID.isnot(None),
models.Package.Name.like(f"%{arg}%"))
).order_by(models.Package.Name.asc()).limit(20)
return [pkg.Name for pkg in packages]
def _handle_suggest_pkgbase_type(self, args: List[str] = []):
records = db.query(models.PackageBase).filter(
and_(models.PackageBase.PackagerUID.isnot(None),
......
......@@ -98,6 +98,17 @@ def setup():
Maintainer=user1,
Packager=user1)
pkgbase4 = create(PackageBase, Name="fugly-chungus",
Maintainer=user1,
Packager=user1)
desc = "A Package belonging to a PackageBase with another name."
create(Package,
PackageBase=pkgbase4,
Name="other-pkg",
Description=desc,
URL="https://example.com")
create(Package,
PackageBase=pkgbase3,
Name=pkgbase3.Name,
......@@ -451,8 +462,19 @@ def test_rpc_suggest_pkgbase():
assert data == ["chungy-chungus"]
def test_rpc_suggest():
response = make_request("/rpc?v=5&type=suggest&arg=other")
data = response.json()
assert data == ["other-pkg"]
# Test non-existent Package.
response = make_request("/rpc?v=5&type=suggest&arg=nonexistent")
data = response.json()
assert data == []
def test_rpc_unimplemented_types():
unimplemented = ["search", "msearch", "suggest"]
unimplemented = ["search", "msearch"]
for type in unimplemented:
response = make_request(f"/rpc?v=5&type={type}&arg=big")
data = response.json()
......
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