Ticket #15502: 15502-test-and-fix.diff
File 15502-test-and-fix.diff, 3.1 KB (added by , 14 years ago) |
---|
-
django/template/loader.py
191 191 192 192 def select_template(template_name_list): 193 193 "Given a list of template names, returns the first that can be loaded." 194 not_found = [] 194 195 for template_name in template_name_list: 195 196 try: 196 197 return get_template(template_name) 197 except TemplateDoesNotExist: 198 except TemplateDoesNotExist, e: 199 if e.args[0] not in not_found: 200 not_found.append(e.args[0]) 198 201 continue 199 202 # If we get here, none of the templates could be loaded 200 raise TemplateDoesNotExist(', '.join( template_name_list))203 raise TemplateDoesNotExist(', '.join(not_found)) 201 204 202 205 add_to_builtins('django.template.loader_tags') -
tests/regressiontests/templates/tests.py
237 237 loader.template_source_loaders = old_loaders 238 238 settings.TEMPLATE_DEBUG = old_td 239 239 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 r = None 260 try: 261 tmpl = loader.select_template([load_name]) 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 240 272 def test_extends_include_missing_baseloader(self): 241 273 """ 242 274 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