0
0
mirror of https://github.com/django/django.git synced 2024-11-21 19:09:18 +01:00

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.
This commit is contained in:
Natalia 2024-11-20 16:39:42 -03:00
parent 55cd3ad41d
commit ccf0b9313e

View File

@ -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})