From ccf0b9313e5ee4d2dd4f5d2bfab9ff04d8531b9e Mon Sep 17 00:00:00 2001 From: Natalia <124304+nessita@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:39:42 -0300 Subject: [PATCH] Refs #10941 -- Added tests in querystring template tag. These extra tests assert over the handling of empty params (None, empty dict, empty QueryDict), and also for dicts having non-string keys. --- .../syntax_tests/test_querystring.py | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/tests/template_tests/syntax_tests/test_querystring.py b/tests/template_tests/syntax_tests/test_querystring.py index 227f2f1b2a..dea8ee0142 100644 --- a/tests/template_tests/syntax_tests/test_querystring.py +++ b/tests/template_tests/syntax_tests/test_querystring.py @@ -13,16 +13,20 @@ class QueryStringTagTests(SimpleTestCase): output = self.engine.render_to_string(template_name, context) self.assertEqual(output, expected) - @setup({"querystring_empty": "{% querystring %}"}) - def test_querystring_empty(self): + @setup({"test_querystring_empty_get_params": "{% querystring %}"}) + def test_querystring_empty_get_params(self): context = RequestContext(self.request_factory.get("/")) - self.assertRenderEqual("querystring_empty", context, expected="") + self.assertRenderEqual( + "test_querystring_empty_get_params", context, expected="" + ) - @setup({"querystring_non_empty": "{% querystring %}"}) - def test_querystring_non_empty(self): + @setup({"test_querystring_non_empty_get_params": "{% querystring %}"}) + def test_querystring_non_empty_get_params(self): request = self.request_factory.get("/", {"a": "b"}) context = RequestContext(request) - self.assertRenderEqual("querystring_non_empty", context, expected="?a=b") + self.assertRenderEqual( + "test_querystring_non_empty_get_params", context, expected="?a=b" + ) @setup({"querystring_multiple": "{% querystring %}"}) def test_querystring_multiple(self): @@ -30,6 +34,17 @@ class QueryStringTagTests(SimpleTestCase): context = RequestContext(request) self.assertRenderEqual("querystring_multiple", context, expected="?x=y&a=b") + @setup({"test_querystring_empty_params": "{% querystring qd %}"}) + def test_querystring_empty_params(self): + cases = [None, {}, QueryDict()] + request = self.request_factory.get("/") + for param in cases: + with self.subTest(param=param): + context = RequestContext(request, {"qd": param}) + self.assertRenderEqual( + "test_querystring_empty_params", context, expected="" + ) + @setup({"querystring_replace": "{% querystring a=1 %}"}) def test_querystring_replace(self): request = self.request_factory.get("/", {"x": "y", "a": "b"}) @@ -64,6 +79,14 @@ class QueryStringTagTests(SimpleTestCase): context = RequestContext(request, {"my_list": [2, 3]}) self.assertRenderEqual("querystring_list", context, expected="?a=2&a=3") + @setup({"querystring_dict": "{% querystring a=my_dict %}"}) + def test_querystring_add_dict(self): + request = self.request_factory.get("/") + context = RequestContext(request, {"my_dict": {i: i * 2 for i in range(3)}}) + self.assertRenderEqual( + "querystring_dict", context, expected="?a=0&a=1&a=2" + ) + @setup({"querystring_query_dict": "{% querystring request.GET a=2 %}"}) def test_querystring_with_explicit_query_dict(self): request = self.request_factory.get("/", {"a": 1})