summaryrefslogtreecommitdiff
path: root/tests/test_utils/tests.py
diff options
context:
space:
mode:
authorCaitie Baca <caitie.baca@powereng.com>2025-09-11 13:06:47 -0700
committerJacob Walls <jacobtylerwalls@gmail.com>2025-09-15 16:45:13 -0400
commit0e0b4214c350da9b627a67987b13ec334e1de033 (patch)
tree84e10f95c8df52de45f8e113550f7451af4c1f8b /tests/test_utils/tests.py
parent6e89271a8507fe272d11814975500a1b40303a04 (diff)
Fixed #36589 -- Made assertTemplateUsed/NotUsed track full path for PartialTemplate.
Previously, assertTemplateUsed only matched partial names, ignoring the template origin. This caused assertions on partials specified by origin ("template.html#partial") to fail. Refs #36410.
Diffstat (limited to 'tests/test_utils/tests.py')
-rw-r--r--tests/test_utils/tests.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 9c22b61b4f..70cca3d441 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -646,6 +646,53 @@ class AssertTemplateUsedContextManagerTests(SimpleTestCase):
self.assertTemplateNotUsed(response, "template.html")
+@override_settings(ROOT_URLCONF="test_utils.urls")
+class AssertTemplateUsedPartialTests(SimpleTestCase):
+ def test_template_used_pass(self):
+ with self.assertTemplateUsed("template_used/partials.html#hello"):
+ render_to_string("template_used/partials.html#hello")
+
+ def test_template_not_used_pass(self):
+ with self.assertTemplateNotUsed("hello"):
+ render_to_string("template_used/partials.html#hello")
+
+ def test_template_used_fail(self):
+ msg = "Template 'hello' was not a template used to render the response."
+ with (
+ self.assertRaisesMessage(AssertionError, msg),
+ self.assertTemplateUsed("hello"),
+ ):
+ render_to_string("template_used/base.html")
+
+ def test_template_not_used_fail(self):
+ msg = (
+ "Template 'template_used/partials.html#hello' was used "
+ "unexpectedly in rendering the response"
+ )
+ with (
+ self.assertRaisesMessage(AssertionError, msg),
+ self.assertTemplateNotUsed("template_used/partials.html#hello"),
+ ):
+ render_to_string("template_used/partials.html#hello")
+
+ def test_template_not_used_pass_non_partial(self):
+ with self.assertTemplateNotUsed(
+ "template_used/base.html#template_used/base.html"
+ ):
+ render_to_string("template_used/base.html")
+
+ def test_template_used_fail_non_partial(self):
+ msg = (
+ "Template 'template_used/base.html#template_used/base.html' was not a "
+ "template used to render the response."
+ )
+ with (
+ self.assertRaisesMessage(AssertionError, msg),
+ self.assertTemplateUsed("template_used/base.html#template_used/base.html"),
+ ):
+ render_to_string("template_used/base.html")
+
+
class HTMLEqualTests(SimpleTestCase):
def test_html_parser(self):
element = parse_html("<div><p>Hello</p></div>")