Ticket #15502: 15502-test.patch

File 15502-test.patch, 2.2 KB (added by James Aylett, 13 years ago)

Failing test

  • tests/regressiontests/templates/tests.py

     
    237237            loader.template_source_loaders = old_loaders
    238238            settings.TEMPLATE_DEBUG = old_td
    239239
     240
     241    def test_include_missing_template(self):
     242        """
     243        Tests that the correct template is identified as not existing
     244        when {% include %} specifies a template that does not exist.
     245        """
     246
     247        # TEMPLATE_DEBUG must be true, otherwise the exception raised
     248        # during {% include %} processing will be suppressed.
     249        old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, True
     250        old_loaders = loader.template_source_loaders
     251
     252        try:
     253            # Test the base loader class via the app loader. load_template
     254            # from base is used by all shipped loaders excepting cached,
     255            # which has its own test.
     256            loader.template_source_loaders = (app_directories.Loader(),)
     257
     258            load_name = 'test_include_error.html'
     259            try:
     260                tmpl = loader.select_template([load_name])
     261                r = None
     262                r = tmpl.render(template.Context({}))
     263            except template.TemplateDoesNotExist, e:
     264                settings.TEMPLATE_DEBUG = old_td
     265                self.assertEqual(e.args[0], 'missing.html')
     266            self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
     267        finally:
     268            loader.template_source_loaders = old_loaders
     269            settings.TEMPLATE_DEBUG = old_td
     270
     271
    240272    def test_extends_include_missing_baseloader(self):
    241273        """
    242274        Tests that the correct template is identified as not existing
  • tests/regressiontests/templates/templates/test_include_error.html

     
     1{% include "missing.html" %}
     2 No newline at end of file
Back to Top