summaryrefslogtreecommitdiff
path: root/django/test
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 /django/test
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 'django/test')
-rw-r--r--django/test/testcases.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 5f0c819815..c587f770a6 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -43,6 +43,7 @@ from django.db.backends.base.base import NO_DB_ALIAS, BaseDatabaseWrapper
from django.forms.fields import CharField
from django.http import QueryDict
from django.http.request import split_domain_port, validate_host
+from django.template.base import PartialTemplate
from django.test.client import AsyncClient, Client
from django.test.html import HTMLParseError, parse_html
from django.test.signals import template_rendered
@@ -138,10 +139,22 @@ class _AssertTemplateUsedContext:
self.rendered_templates.append(template)
self.context.append(copy(context))
+ @property
+ def rendered_template_names(self):
+ return [
+ (
+ f"{t.origin.template_name}#{t.name}"
+ if isinstance(t, PartialTemplate)
+ else t.name
+ )
+ for t in self.rendered_templates
+ if t.name is not None
+ ]
+
def test(self):
self.test_case._assert_template_used(
self.template_name,
- [t.name for t in self.rendered_templates if t.name is not None],
+ self.rendered_template_names,
self.msg_prefix,
self.count,
)
@@ -159,11 +172,8 @@ class _AssertTemplateUsedContext:
class _AssertTemplateNotUsedContext(_AssertTemplateUsedContext):
def test(self):
- rendered_template_names = [
- t.name for t in self.rendered_templates if t.name is not None
- ]
self.test_case.assertFalse(
- self.template_name in rendered_template_names,
+ self.template_name in self.rendered_template_names,
f"{self.msg_prefix}Template '{self.template_name}' was used "
f"unexpectedly in rendering the response",
)