mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #34823 -- Fixed assertTemplateUsed() context manager crash on unnamed templates.
This commit is contained in:
@@ -26,6 +26,7 @@ from django.forms import (
|
||||
formset_factory,
|
||||
)
|
||||
from django.http import HttpResponse
|
||||
from django.template import Context, Template
|
||||
from django.template.loader import render_to_string
|
||||
from django.test import (
|
||||
SimpleTestCase,
|
||||
@@ -530,12 +531,20 @@ class AssertTemplateUsedContextManagerTests(SimpleTestCase):
|
||||
with self.assertTemplateUsed("template_used/base.html"):
|
||||
render_to_string("template_used/alternative.html")
|
||||
|
||||
with self.assertRaisesMessage(
|
||||
AssertionError, "No templates used to render the response"
|
||||
):
|
||||
msg = "No templates used to render the response"
|
||||
with self.assertRaisesMessage(AssertionError, msg):
|
||||
response = self.client.get("/test_utils/no_template_used/")
|
||||
self.assertTemplateUsed(response, "template_used/base.html")
|
||||
|
||||
with self.assertRaisesMessage(AssertionError, msg):
|
||||
with self.assertTemplateUsed("template_used/base.html"):
|
||||
self.client.get("/test_utils/no_template_used/")
|
||||
|
||||
with self.assertRaisesMessage(AssertionError, msg):
|
||||
with self.assertTemplateUsed("template_used/base.html"):
|
||||
template = Template("template_used/alternative.html", name=None)
|
||||
template.render(Context())
|
||||
|
||||
def test_msg_prefix(self):
|
||||
msg_prefix = "Prefix"
|
||||
msg = f"{msg_prefix}: No templates used to render the response"
|
||||
|
||||
Reference in New Issue
Block a user