Skip to content

Commit 0780294

Browse files
committed
Fix querystring parse test util
1 parent e162265 commit 0780294

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tests/test_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
from stac_auth_proxy.utils.requests import extract_variables
6+
from utils import parse_query_string
67

78

89
@pytest.mark.parametrize(
@@ -19,3 +20,18 @@
1920
def test_extract_variables(url, expected):
2021
"""Test extracting variables from a URL path."""
2122
assert extract_variables(url) == expected
23+
24+
25+
@pytest.mark.parametrize(
26+
"query, expected",
27+
(
28+
("foo=bar", {"foo": "bar"}),
29+
(
30+
'filter={"xyz":"abc"}&filter-lang=cql2-json',
31+
{"filter": {"xyz": "abc"}, "filter-lang": "cql2-json"},
32+
),
33+
),
34+
)
35+
def test_parse_query_string(query, expected):
36+
"""Validate test helper for parsing query strings."""
37+
assert parse_query_string(query) == expected

tests/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ def single_chunk_async_stream_response(
5454

5555
def parse_query_string(qs: str) -> dict:
5656
"""Parse a query string into a dictionary."""
57+
# Python's parse_qs will turn dicts into strings (e.g. parse_qs('foo={"x":"y"}') == {'foo': ['{"x":"y"}']})
58+
# so we need some special tooling to examine the query params and compare them to expected values
5759
parsed = parse_qs(qs)
5860

5961
result = {}
6062
for key, value_list in parsed.items():
6163
value = value_list[0]
62-
if key == "filter" and parsed.get("filter-lang") == "cql2-json":
64+
if key == "filter" and parsed.get("filter-lang") == ["cql2-json"]:
6365
decoded_str = unquote(value)
6466
result[key] = json.loads(decoded_str)
6567
else:

0 commit comments

Comments
 (0)