summaryrefslogtreecommitdiff
path: root/tests/regressiontests/templates
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2011-03-03 00:42:56 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2011-03-03 00:42:56 +0000
commitac87e4f8fa5f7242a5dc274436891a50a8a60904 (patch)
tree822a8c1ce3377def529fa632f2481e7923f9e919 /tests/regressiontests/templates
parent4c76896eada07f25d143e0d78989240f5ad8e020 (diff)
[1.2.X] Fixed #15502 -- Ensure that nested TemplateDoesNotExist errors are propegated with a meaningful error message when loaded using select_template. Thanks to jaylett for the report, and GDorn for the patch.
Backport of r15717 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15718 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/templates')
-rw-r--r--tests/regressiontests/templates/templates/test_include_error.html1
-rw-r--r--tests/regressiontests/templates/tests.py32
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/regressiontests/templates/templates/test_include_error.html b/tests/regressiontests/templates/templates/test_include_error.html
new file mode 100644
index 0000000000..6db959380e
--- /dev/null
+++ b/tests/regressiontests/templates/templates/test_include_error.html
@@ -0,0 +1 @@
+{% include "missing.html" %} \ No newline at end of file
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 6c19f70b7b..dfbc24d025 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -205,6 +205,38 @@ class Templates(unittest.TestCase):
loader.template_source_loaders = old_loaders
settings.TEMPLATE_DEBUG = old_td
+
+ def test_include_missing_template(self):
+ """
+ Tests that the correct template is identified as not existing
+ when {% include %} specifies a template that does not exist.
+ """
+
+ # TEMPLATE_DEBUG must be true, otherwise the exception raised
+ # during {% include %} processing will be suppressed.
+ old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, True
+ old_loaders = loader.template_source_loaders
+
+ try:
+ # Test the base loader class via the app loader. load_template
+ # from base is used by all shipped loaders excepting cached,
+ # which has its own test.
+ loader.template_source_loaders = (app_directories.Loader(),)
+
+ load_name = 'test_include_error.html'
+ r = None
+ try:
+ tmpl = loader.select_template([load_name])
+ r = tmpl.render(template.Context({}))
+ except template.TemplateDoesNotExist, e:
+ settings.TEMPLATE_DEBUG = old_td
+ self.assertEqual(e.args[0], 'missing.html')
+ self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
+ finally:
+ loader.template_source_loaders = old_loaders
+ settings.TEMPLATE_DEBUG = old_td
+
+
def test_extends_include_missing_baseloader(self):
"""
Tests that the correct template is identified as not existing