Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Arch Linux
aurweb
Commits
efd20ed2
Verified
Commit
efd20ed2
authored
Nov 08, 2022
by
Mario Oenning
Browse files
feat(rpc): add "by" parameter - keywords
Add "by" parameter: keywords Signed-off-by:
moson-mo
<
mo-son@mailbox.org
>
parent
5484e68b
Changes
3
Hide whitespace changes
Inline
Side-by-side
aurweb/packages/search.py
View file @
efd20ed2
...
...
@@ -269,7 +269,7 @@ class RPCSearch(PackageSearch):
sanitization done for the PackageSearch `by` argument.
"""
keys_removed
=
(
"b"
,
"N"
,
"B"
,
"k"
,
"c"
,
"M"
)
keys_removed
=
(
"b"
,
"N"
,
"B"
,
"c"
,
"M"
)
def
__init__
(
self
)
->
"RPCSearch"
:
super
().
__init__
()
...
...
@@ -372,11 +372,16 @@ class RPCSearch(PackageSearch):
)
return
self
def
_search_by_groups
(
self
,
keywords
:
str
)
->
orm
.
Query
:
def
_search_by_groups
(
self
,
keywords
:
str
)
->
"RPCSearch"
:
self
.
_join_groups
()
self
.
query
=
self
.
query
.
filter
(
Group
.
Name
==
keywords
)
return
self
def
_search_by_keywords
(
self
,
keywords
:
str
)
->
"RPCSearch"
:
self
.
_join_keywords
()
self
.
query
=
self
.
query
.
filter
(
PackageKeyword
.
Keyword
==
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`
...
...
aurweb/rpc.py
View file @
efd20ed2
...
...
@@ -88,10 +88,17 @@ class RPC:
"replaces"
,
"groups"
,
"submitter"
,
"keywords"
,
}
# A mapping of by aliases.
BY_ALIASES
=
{
"name-desc"
:
"nd"
,
"name"
:
"n"
,
"maintainer"
:
"m"
,
"submitter"
:
"s"
}
BY_ALIASES
=
{
"name-desc"
:
"nd"
,
"name"
:
"n"
,
"maintainer"
:
"m"
,
"submitter"
:
"s"
,
"keywords"
:
"k"
,
}
def
__init__
(
self
,
version
:
int
=
0
,
type
:
str
=
None
)
->
"RPC"
:
self
.
version
=
version
...
...
test/test_rpc.py
View file @
efd20ed2
...
...
@@ -938,6 +938,25 @@ def test_rpc_search_submitter(client: TestClient, user2: User, packages: list[Pa
assert
data
.
get
(
"resultcount"
)
==
0
def
test_rpc_search_keywords
(
client
:
TestClient
,
packages
:
list
[
Package
]):
params
=
{
"v"
:
5
,
"type"
:
"search"
,
"by"
:
"keywords"
,
"arg"
:
"big-chungus"
}
with
client
as
request
:
response
=
request
.
get
(
"/rpc"
,
params
=
params
)
data
=
response
.
json
()
# should get 2 packages
assert
data
.
get
(
"resultcount"
)
==
1
names
=
list
(
sorted
(
r
.
get
(
"Name"
)
for
r
in
data
.
get
(
"results"
)))
expected_results
=
[
"big-chungus"
]
assert
names
==
expected_results
# non-existent search
params
[
"arg"
]
=
"blah-blah"
response
=
request
.
get
(
"/rpc"
,
params
=
params
)
data
=
response
.
json
()
assert
data
.
get
(
"resultcount"
)
==
0
def
test_rpc_incorrect_by
(
client
:
TestClient
):
params
=
{
"v"
:
5
,
"type"
:
"search"
,
"by"
:
"fake"
,
"arg"
:
"big"
}
with
client
as
request
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment