From a492c12752382202664aa2bf89ee4f0823a8a2d2 Mon Sep 17 00:00:00 2001 From: Nachiket Date: Sun, 31 May 2026 19:26:51 -0700 Subject: [PATCH] test: cover indexed query array parameters --- tests/test_qs.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_qs.py b/tests/test_qs.py index 564a41e61..fd7a6dca9 100644 --- a/tests/test_qs.py +++ b/tests/test_qs.py @@ -73,6 +73,18 @@ def test_array_brackets(method: str) -> None: assert unquote(serialise({"a": {"b": [True, False, None, True]}})) == "a[b][]=true&a[b][]=false&a[b][]=true" +@pytest.mark.parametrize("method", ["class", "function"]) +def test_array_indices(method: str) -> None: + if method == "class": + serialise = Querystring(array_format="indices").stringify + else: + serialise = partial(stringify, array_format="indices") + + assert unquote(serialise({"in": ["foo", "bar"]})) == "in[0]=foo&in[1]=bar" + assert unquote(serialise({"a": {"b": [True, False]}})) == "a[b][0]=true&a[b][1]=false" + assert unquote(serialise({"a": {"b": [True, False, None, True]}})) == "a[b][0]=true&a[b][1]=false&a[b][3]=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"))