Ticket #16866: handle_empty_list_of_templates.2.diff

File handle_empty_list_of_templates.2.diff, 1.3 KB (added by Silver_Ghost, 13 years ago)

Switching to TemplateDoesNotExist exception and adding tests

  • django/template/loader.py

    diff --git a/django/template/loader.py b/django/template/loader.py
    a b  
    179179
    180180def select_template(template_name_list):
    181181    "Given a list of template names, returns the first that can be loaded."
     182    if template_name_list is not None and not template_name_list:
     183        raise TemplateDoesNotExist("empty list of candidates")
    182184    not_found = []
    183185    for template_name in template_name_list:
    184186        try:
  • tests/regressiontests/templates/loaders.py

    diff --git a/tests/regressiontests/templates/loaders.py b/tests/regressiontests/templates/loaders.py
    a b  
    143143        self.assertEqual(output, 'obj:after')
    144144        self.assertEqual(context['obj'], 'before')
    145145
     146    def test_empty_list(self):
     147        self.assertRaisesRegexp(TemplateDoesNotExist,
     148                                'empty list of candidates$',
     149                                loader.render_to_string, [])
     150
     151
     152    def test_select_templates_from_empty_list(self):
     153        self.assertRaisesRegexp(TemplateDoesNotExist,
     154                                'empty list of candidates$',
     155                                loader.select_template, [])
     156
    146157if __name__ == "__main__":
    147158    unittest.main()
Back to Top