Verified Commit 50287cb0 authored by Mario Oenning's avatar Mario Oenning
Browse files

feat(rpc): add "by" parameters - package relations



This adds new "by" search-parameters: provides, conflicts and replaces

Signed-off-by: Mario Oenning's avatarmoson-mo <mo-son@mailbox.org>
parent 73f0bddf
......@@ -14,6 +14,7 @@ from aurweb.models.package_comaintainer import PackageComaintainer
from aurweb.models.package_keyword import PackageKeyword
from aurweb.models.package_notification import PackageNotification
from aurweb.models.package_vote import PackageVote
from aurweb.models.relation_type import CONFLICTS_ID, PROVIDES_ID, REPLACES_ID
class PackageSearch:
......@@ -286,6 +287,9 @@ class RPCSearch(PackageSearch):
"makedepends": self._search_by_makedepends,
"optdepends": self._search_by_optdepends,
"checkdepends": self._search_by_checkdepends,
"provides": self._search_by_provides,
"conflicts": self._search_by_conflicts,
"replaces": self._search_by_replaces,
}
)
......@@ -304,6 +308,18 @@ class RPCSearch(PackageSearch):
)
return self.query
def _join_relations(self, rel_type_id: int) -> orm.Query:
"""Join Package with PackageRelation and filter results
based on `rel_type_id`.
:param rel_type_id: RelationType ID
:returns: PackageRelation-joined orm.Query
"""
self.query = self.query.join(models.PackageRelation).filter(
models.PackageRelation.RelTypeID == rel_type_id
)
return self.query
def _search_by_depends(self, keywords: str) -> "RPCSearch":
self.query = self._join_depends(DEPENDS_ID).filter(
models.PackageDependency.DepName == keywords
......@@ -328,6 +344,24 @@ class RPCSearch(PackageSearch):
)
return self
def _search_by_provides(self, keywords: str) -> "RPCSearch":
self.query = self._join_relations(PROVIDES_ID).filter(
models.PackageRelation.RelName == keywords
)
return self
def _search_by_conflicts(self, keywords: str) -> "RPCSearch":
self.query = self._join_relations(CONFLICTS_ID).filter(
models.PackageRelation.RelName == keywords
)
return self
def _search_by_replaces(self, keywords: str) -> "RPCSearch":
self.query = self._join_relations(REPLACES_ID).filter(
models.PackageRelation.RelName == keywords
)
return self
def search_by(self, by: str, keywords: str) -> "RPCSearch":
"""Override inherited search_by. In this override, we reduce the
scope of what we handle within this function. We do not set `by`
......
......@@ -83,6 +83,9 @@ class RPC:
"makedepends",
"optdepends",
"checkdepends",
"provides",
"conflicts",
"replaces",
}
# A mapping of by aliases.
......
......@@ -852,6 +852,42 @@ def test_rpc_search_checkdepends(
assert result.get("Name") == packages[0].Name
def test_rpc_search_provides(
client: TestClient, packages: list[Package], relations: list[PackageRelation]
):
params = {"v": 5, "type": "search", "by": "provides", "arg": "chungus-provides"}
with client as request:
response = request.get("/rpc", params=params)
data = response.json()
assert data.get("resultcount") == 1
result = data.get("results")[0]
assert result.get("Name") == packages[0].Name
def test_rpc_search_conflicts(
client: TestClient, packages: list[Package], relations: list[PackageRelation]
):
params = {"v": 5, "type": "search", "by": "conflicts", "arg": "chungus-conflicts"}
with client as request:
response = request.get("/rpc", params=params)
data = response.json()
assert data.get("resultcount") == 1
result = data.get("results")[0]
assert result.get("Name") == packages[0].Name
def test_rpc_search_replaces(
client: TestClient, packages: list[Package], relations: list[PackageRelation]
):
params = {"v": 5, "type": "search", "by": "replaces", "arg": "chungus-replaces"}
with client as request:
response = request.get("/rpc", params=params)
data = response.json()
assert data.get("resultcount") == 1
result = data.get("results")[0]
assert result.get("Name") == packages[0].Name
def test_rpc_incorrect_by(client: TestClient):
params = {"v": 5, "type": "search", "by": "fake", "arg": "big"}
with client as request:
......
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