Skip to content

Commit

Permalink
Refs django#10941 -- Added tests in querystring template tag.
Browse files Browse the repository at this point in the history
These extra tests assert over the handling of empty params (None, empty
dict, empty QueryDict), and also for dicts having non-string keys.
  • Loading branch information
nessita committed Nov 20, 2024
1 parent ab106c3 commit ecd8df1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/template_tests/syntax_tests/test_querystring.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def test_querystring_multiple(self):
request = self.request_factory.get("/", {"x": "y", "a": "b"})
self.assertRenderEqual("querystring_multiple", request, expected="?x=y&a=b")

@setup({"test_querystring_empty_params": "{% querystring qd %}"})
def test_querystring_empty_params(self):
cases = [None, {}, QueryDict()]
for param in cases:
with self.subTest(param=param):
self.assertRenderEqual(
"test_querystring_empty_params", qd=param, expected=""
)

@setup({"querystring_replace": "{% querystring a=1 %}"})
def test_querystring_replace(self):
request = self.request_factory.get("/", {"x": "y", "a": "b"})
Expand Down Expand Up @@ -62,6 +71,14 @@ def test_querystring_add_list(self):
"querystring_list", my_list=[2, 3], expected="?a=2&a=3"
)

@setup({"querystring_dict": "{% querystring a=my_dict %}"})
def test_querystring_add_dict(self):
self.assertRenderEqual(
"querystring_dict",
my_dict={i: i * 2 for i in range(3)},
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})
Expand Down

0 comments on commit ecd8df1

Please sign in to comment.