Verified Commit a1a88ea8 authored by Kevin Morris's avatar Kevin Morris
Browse files

fix(rpc): suggestions should only suggest based on <keyword>%

Previously, Python code was looking for suggestions based on
`%<keyword>%`. This was inconsistent with PHP's suggestion
implementation and cause more records to be bundled with a suggestion,
along with supplying misleading suggestions.

Closes #343



Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 97917046
......@@ -332,7 +332,7 @@ class RPC:
models.PackageBase
).filter(
and_(models.PackageBase.PackagerUID.isnot(None),
models.Package.Name.like(f"%{arg}%"))
models.Package.Name.like(f"{arg}%"))
).order_by(models.Package.Name.asc()).limit(20)
return [pkg.Name for pkg in packages]
......@@ -341,9 +341,10 @@ class RPC:
if not args:
return []
arg = args[0]
packages = db.query(models.PackageBase.Name).filter(
and_(models.PackageBase.PackagerUID.isnot(None),
models.PackageBase.Name.like(f"%{args[0]}%"))
models.PackageBase.Name.like(f"{arg}%"))
).order_by(models.PackageBase.Name.asc()).limit(20)
return [pkg.Name for pkg in packages]
......
......@@ -551,6 +551,14 @@ def test_rpc_suggest_pkgbase(client: TestClient, packages: List[Package]):
data = response.json()
assert data == []
# Test that suggestions are only given based on the beginning
# of the keyword string.
params["arg"] = "ther-pkg"
with client as request:
response = request.get("/rpc", params=params)
data = response.json()
assert data == []
def test_rpc_suggest(client: TestClient, packages: List[Package]):
params = {"v": 5, "type": "suggest", "arg": "other"}
......@@ -573,6 +581,14 @@ def test_rpc_suggest(client: TestClient, packages: List[Package]):
data = response.json()
assert data == []
# Test that suggestions are only given based on the beginning
# of the keyword string.
params["arg"] = "ther-pkg"
with client as request:
response = request.get("/rpc", params=params)
data = response.json()
assert data == []
def mock_config_getint(section: str, key: str):
if key == "request_limit":
......
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