mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
aurweb.util: add extend_query and to_qs helpers
The first addition, extend_query, can be used to take an existing query parameter dictionary and inject an *additions as replacement key/value pairs. The second, to_qs, converts a query parameter dictionary to a query string in the form "a=b&c=d". These two functions simplify and make dedupe_qs and quote_plus more efficient in terms of constructing custom query string overrides. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
49cc12f99d
commit
a114bd3e16
2 changed files with 28 additions and 1 deletions
|
@ -35,3 +35,18 @@ def test_dedupe_qs():
|
|||
def test_number_format():
|
||||
assert util.number_format(0.222, 2) == "0.22"
|
||||
assert util.number_format(0.226, 2) == "0.23"
|
||||
|
||||
|
||||
def test_extend_query():
|
||||
""" Test extension of a query via extend_query. """
|
||||
query = {"a": "b"}
|
||||
extended = util.extend_query(query, ("a", "c"), ("b", "d"))
|
||||
assert extended.get("a") == "c"
|
||||
assert extended.get("b") == "d"
|
||||
|
||||
|
||||
def test_to_qs():
|
||||
""" Test conversion from a query dictionary to a query string. """
|
||||
query = {"a": "b", "c": [1, 2, 3]}
|
||||
qs = util.to_qs(query)
|
||||
assert qs == "a=b&c=1&c=2&c=3"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue