mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Refs #27175 -- Removed exception silencing from the {% include %} template tag.
Per deprecation timeline.
This commit is contained in:
parent
96107e2844
commit
e62165b898
6 changed files with 37 additions and 161 deletions
|
@ -1,8 +1,7 @@
|
|||
import logging
|
||||
|
||||
from django.template import Context, Engine, Variable, VariableDoesNotExist
|
||||
from django.test import SimpleTestCase, ignore_warnings
|
||||
from django.utils.deprecation import RemovedInDjango21Warning
|
||||
from django.template import Engine, Variable, VariableDoesNotExist
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
|
||||
class TestHandler(logging.Handler):
|
||||
|
@ -81,46 +80,3 @@ class VariableResolveLoggingTests(BaseTemplateLoggingTestCase):
|
|||
def test_no_log_when_variable_exists(self):
|
||||
Variable('article.section').resolve({'article': {'section': 'News'}})
|
||||
self.assertIsNone(self.test_handler.log_record)
|
||||
|
||||
|
||||
class IncludeNodeLoggingTests(BaseTemplateLoggingTestCase):
|
||||
loglevel = logging.WARN
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.engine = Engine(loaders=[
|
||||
('django.template.loaders.locmem.Loader', {
|
||||
'child': '{{ raises_exception }}',
|
||||
}),
|
||||
], debug=False)
|
||||
|
||||
def error_method():
|
||||
raise IndexError("some generic exception")
|
||||
|
||||
cls.ctx = Context({'raises_exception': error_method})
|
||||
|
||||
def test_logs_exceptions_during_rendering_with_debug_disabled(self):
|
||||
template = self.engine.from_string('{% include "child" %}')
|
||||
template.name = 'template_name'
|
||||
with ignore_warnings(category=RemovedInDjango21Warning):
|
||||
self.assertEqual(template.render(self.ctx), '')
|
||||
self.assertEqual(
|
||||
self.test_handler.log_record.getMessage(),
|
||||
"Exception raised while rendering {% include %} for template "
|
||||
"'template_name'. Empty string rendered instead."
|
||||
)
|
||||
self.assertIsNotNone(self.test_handler.log_record.exc_info)
|
||||
self.assertEqual(self.test_handler.log_record.levelno, logging.WARN)
|
||||
|
||||
def test_logs_exceptions_during_rendering_with_no_template_name(self):
|
||||
template = self.engine.from_string('{% include "child" %}')
|
||||
with ignore_warnings(category=RemovedInDjango21Warning):
|
||||
self.assertEqual(template.render(self.ctx), '')
|
||||
self.assertEqual(
|
||||
self.test_handler.log_record.getMessage(),
|
||||
"Exception raised while rendering {% include %} for template "
|
||||
"'unknown'. Empty string rendered instead."
|
||||
)
|
||||
self.assertIsNotNone(self.test_handler.log_record.exc_info)
|
||||
self.assertEqual(self.test_handler.log_record.levelno, logging.WARN)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue