Skip to content

Commit

Permalink
test(qs): add an additional test case for array brackets (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Oct 27, 2023
1 parent e0b6a17 commit e3bda02
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def test_array_repeat() -> None:
assert unquote(stringify({"in": ["foo", {"b": {"c": ["d", "e"]}}]})) == "in=foo&in[b][c]=d&in[b][c]=e"


@pytest.mark.parametrize("method", ["class", "function"])
def test_array_brackets(method: str) -> None:
if method == "class":
serialise = Querystring(array_format="brackets").stringify
else:
serialise = partial(stringify, array_format="brackets")

assert unquote(serialise({"in": ["foo", "bar"]})) == "in[]=foo&in[]=bar"
assert unquote(serialise({"a": {"b": [True, False]}})) == "a[b][]=true&a[b][]=false"
assert unquote(serialise({"a": {"b": [True, False, None, True]}})) == "a[b][]=true&a[b][]=false&a[b][]=true"


def test_unknown_array_format() -> None:
with pytest.raises(NotImplementedError, match="Unknown array_format value: foo, choose from comma, repeat"):
stringify({"a": ["foo", "bar"]}, array_format=cast(Any, "foo"))

0 comments on commit e3bda02

Please sign in to comment.