diff options
| author | Natalia <124304+nessita@users.noreply.github.com> | 2024-11-20 16:39:42 -0300 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-11-29 08:27:11 +0100 |
| commit | 15ca75449bcab3ec5b36dc7a17a0898ac8013621 (patch) | |
| tree | 48f9723c24a978172932f4401f4355286638f4b6 /tests/template_tests/syntax_tests/test_querystring.py | |
| parent | f2b44ef40851232dd7b92fcffb2a631012845939 (diff) | |
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.
Diffstat (limited to 'tests/template_tests/syntax_tests/test_querystring.py')
| -rw-r--r-- | tests/template_tests/syntax_tests/test_querystring.py | 35 |
1 files 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}) |
