summaryrefslogtreecommitdiff
path: root/tests/template_tests
diff options
context:
space:
mode:
authorNatalia <124304+nessita@users.noreply.github.com>2024-11-20 16:29:40 -0300
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-11-29 08:27:11 +0100
commitf2b44ef40851232dd7b92fcffb2a631012845939 (patch)
tree4f598511ff5b353e8b7d83c2517d8c262c73a856 /tests/template_tests
parentceecd518b19044181a3598c55ebed7c2545963cc (diff)
Refs #10941 -- Added helper and refactored tests for querystring template tag.
Thank you Sarah Boyce for the review and suggestions.
Diffstat (limited to 'tests/template_tests')
-rw-r--r--tests/template_tests/syntax_tests/test_querystring.py57
1 files changed, 23 insertions, 34 deletions
diff --git a/tests/template_tests/syntax_tests/test_querystring.py b/tests/template_tests/syntax_tests/test_querystring.py
index 3f1cf3d281..227f2f1b2a 100644
--- a/tests/template_tests/syntax_tests/test_querystring.py
+++ b/tests/template_tests/syntax_tests/test_querystring.py
@@ -6,88 +6,77 @@ from ..utils import setup
class QueryStringTagTests(SimpleTestCase):
- def setUp(self):
- self.request_factory = RequestFactory()
+
+ request_factory = RequestFactory()
+
+ def assertRenderEqual(self, template_name, context, expected):
+ output = self.engine.render_to_string(template_name, context)
+ self.assertEqual(output, expected)
@setup({"querystring_empty": "{% querystring %}"})
def test_querystring_empty(self):
- request = self.request_factory.get("/")
- template = self.engine.get_template("querystring_empty")
- context = RequestContext(request)
- output = template.render(context)
- self.assertEqual(output, "")
+ context = RequestContext(self.request_factory.get("/"))
+ self.assertRenderEqual("querystring_empty", context, expected="")
@setup({"querystring_non_empty": "{% querystring %}"})
def test_querystring_non_empty(self):
request = self.request_factory.get("/", {"a": "b"})
- template = self.engine.get_template("querystring_non_empty")
context = RequestContext(request)
- output = template.render(context)
- self.assertEqual(output, "?a=b")
+ self.assertRenderEqual("querystring_non_empty", context, expected="?a=b")
@setup({"querystring_multiple": "{% querystring %}"})
def test_querystring_multiple(self):
request = self.request_factory.get("/", {"x": "y", "a": "b"})
- template = self.engine.get_template("querystring_multiple")
context = RequestContext(request)
- output = template.render(context)
- self.assertEqual(output, "?x=y&amp;a=b")
+ self.assertRenderEqual("querystring_multiple", context, expected="?x=y&amp;a=b")
@setup({"querystring_replace": "{% querystring a=1 %}"})
def test_querystring_replace(self):
request = self.request_factory.get("/", {"x": "y", "a": "b"})
- template = self.engine.get_template("querystring_replace")
context = RequestContext(request)
- output = template.render(context)
- self.assertEqual(output, "?x=y&amp;a=1")
+ self.assertRenderEqual("querystring_replace", context, expected="?x=y&amp;a=1")
@setup({"querystring_add": "{% querystring test_new='something' %}"})
def test_querystring_add(self):
request = self.request_factory.get("/", {"a": "b"})
- template = self.engine.get_template("querystring_add")
context = RequestContext(request)
- output = template.render(context)
- self.assertEqual(output, "?a=b&amp;test_new=something")
+ self.assertRenderEqual(
+ "querystring_add", context, expected="?a=b&amp;test_new=something"
+ )
@setup({"querystring_remove": "{% querystring test=None a=1 %}"})
def test_querystring_remove(self):
request = self.request_factory.get("/", {"test": "value", "a": "1"})
- template = self.engine.get_template("querystring_remove")
context = RequestContext(request)
- output = template.render(context)
- self.assertEqual(output, "?a=1")
+ self.assertRenderEqual("querystring_remove", context, expected="?a=1")
@setup({"querystring_remove_nonexistent": "{% querystring nonexistent=None a=1 %}"})
def test_querystring_remove_nonexistent(self):
request = self.request_factory.get("/", {"x": "y", "a": "1"})
- template = self.engine.get_template("querystring_remove_nonexistent")
context = RequestContext(request)
- output = template.render(context)
- self.assertEqual(output, "?x=y&amp;a=1")
+ self.assertRenderEqual(
+ "querystring_remove_nonexistent", context, expected="?x=y&amp;a=1"
+ )
@setup({"querystring_list": "{% querystring a=my_list %}"})
def test_querystring_add_list(self):
request = self.request_factory.get("/")
- template = self.engine.get_template("querystring_list")
context = RequestContext(request, {"my_list": [2, 3]})
- output = template.render(context)
- self.assertEqual(output, "?a=2&amp;a=3")
+ self.assertRenderEqual("querystring_list", context, expected="?a=2&amp;a=3")
@setup({"querystring_query_dict": "{% querystring request.GET a=2 %}"})
def test_querystring_with_explicit_query_dict(self):
request = self.request_factory.get("/", {"a": 1})
- output = self.engine.render_to_string(
- "querystring_query_dict", {"request": request}
+ self.assertRenderEqual(
+ "querystring_query_dict", {"request": request}, expected="?a=2"
)
- self.assertEqual(output, "?a=2")
@setup({"querystring_query_dict_no_request": "{% querystring my_query_dict a=2 %}"})
def test_querystring_with_explicit_query_dict_and_no_request(self):
context = {"my_query_dict": QueryDict("a=1&b=2")}
- output = self.engine.render_to_string(
- "querystring_query_dict_no_request", context
+ self.assertRenderEqual(
+ "querystring_query_dict_no_request", context, expected="?a=2&amp;b=2"
)
- self.assertEqual(output, "?a=2&amp;b=2")
@setup({"querystring_no_request_no_query_dict": "{% querystring %}"})
def test_querystring_without_request_or_explicit_query_dict(self):