summaryrefslogtreecommitdiff
path: root/tests/regressiontests/templates
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2010-03-01 23:05:35 +0000
committerKaren Tracey <kmtracey@gmail.com>2010-03-01 23:05:35 +0000
commit698410ab6fd480c4ea08a7adfb4694404ef9ba15 (patch)
tree6c1943f3823d60db5a149e85ebcb4004abfa19c4 /tests/regressiontests/templates
parent973bf6f4856ec3769398caa643ccc61dff4b19f4 (diff)
Fixed #12992: Adjusted the new template loader code so that the template
file name is correctly reported on the debug page when a template syntax error is raised. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12643 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/templates')
-rw-r--r--tests/regressiontests/templates/tests.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 307feccac0..31c9e249a9 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -155,6 +155,43 @@ class Templates(unittest.TestCase):
test_template_sources('/DIR1/index.HTML', template_dirs,
['/dir1/index.html'])
+ def test_loader_debug_origin(self):
+ # Turn TEMPLATE_DEBUG on, so that the origin file name will be kept with
+ # the compiled templates.
+ old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, True
+
+ old_loaders = loader.template_source_loaders
+ loader.template_source_loaders = (filesystem.Loader(),)
+
+ # We rely on the fact that runtests.py sets up TEMPLATE_DIRS to
+ # point to a directory containing a 404.html file. Also that
+ # the file system and app directories loaders both inherit the
+ # load_template method from the BaseLoader class, so we only need
+ # to test one of them.
+ load_name = '404.html'
+ template = loader.get_template(load_name)
+ template_name = template.nodelist[0].source[0].name
+ self.assertTrue(template_name.endswith(load_name),
+ 'Template loaded by filesystem loader has incorrect name for debug page: %s' % template_name)
+
+ # Aso test the cached loader, since it overrides load_template
+ cache_loader = cached.Loader(('',))
+ cache_loader._cached_loaders = loader.template_source_loaders
+ loader.template_source_loaders = (cache_loader,)
+
+ template = loader.get_template(load_name)
+ template_name = template.nodelist[0].source[0].name
+ self.assertTrue(template_name.endswith(load_name),
+ 'Template loaded through cached loader has incorrect name for debug page: %s' % template_name)
+
+ template = loader.get_template(load_name)
+ template_name = template.nodelist[0].source[0].name
+ self.assertTrue(template_name.endswith(load_name),
+ 'Cached template loaded through cached loader has incorrect name for debug page: %s' % template_name)
+
+ loader.template_source_loaders = old_loaders
+ settings.TEMPLATE_DEBUG = old_td
+
def test_token_smart_split(self):
# Regression test for #7027
token = template.Token(template.TOKEN_BLOCK, 'sometag _("Page not found") value|yesno:_("yes,no")')