Skip to content

Commit ed4f931

Browse files
committed
test(qs): add an additional test case for array brackets (#14)
1 parent 14f34e1 commit ed4f931

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/test_qs.py

+12
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ def test_array_repeat() -> None:
6161
assert unquote(stringify({"in": ["foo", {"b": {"c": ["d", "e"]}}]})) == "in=foo&in[b][c]=d&in[b][c]=e"
6262

6363

64+
@pytest.mark.parametrize("method", ["class", "function"])
65+
def test_array_brackets(method: str) -> None:
66+
if method == "class":
67+
serialise = Querystring(array_format="brackets").stringify
68+
else:
69+
serialise = partial(stringify, array_format="brackets")
70+
71+
assert unquote(serialise({"in": ["foo", "bar"]})) == "in[]=foo&in[]=bar"
72+
assert unquote(serialise({"a": {"b": [True, False]}})) == "a[b][]=true&a[b][]=false"
73+
assert unquote(serialise({"a": {"b": [True, False, None, True]}})) == "a[b][]=true&a[b][]=false&a[b][]=true"
74+
75+
6476
def test_unknown_array_format() -> None:
6577
with pytest.raises(NotImplementedError, match="Unknown array_format value: foo, choose from comma, repeat"):
6678
stringify({"a": ["foo", "bar"]}, array_format=cast(Any, "foo"))

0 commit comments

Comments
 (0)