1. from django.template import TemplateDoesNotExist, TemplateSyntaxError
    
  2. from django.test import SimpleTestCase
    
  3. 
    
  4. from ..utils import setup
    
  5. from .test_extends import inheritance_templates
    
  6. 
    
  7. 
    
  8. class ExceptionsTests(SimpleTestCase):
    
  9.     @setup({"exception01": "{% extends 'nonexistent' %}"})
    
  10.     def test_exception01(self):
    
  11.         """
    
  12.         Raise exception for invalid template name
    
  13.         """
    
  14.         with self.assertRaises(TemplateDoesNotExist):
    
  15.             self.engine.render_to_string("exception01")
    
  16. 
    
  17.     @setup({"exception02": "{% extends nonexistent %}"})
    
  18.     def test_exception02(self):
    
  19.         """
    
  20.         Raise exception for invalid variable template name
    
  21.         """
    
  22.         if self.engine.string_if_invalid:
    
  23.             with self.assertRaises(TemplateDoesNotExist):
    
  24.                 self.engine.render_to_string("exception02")
    
  25.         else:
    
  26.             with self.assertRaises(TemplateSyntaxError):
    
  27.                 self.engine.render_to_string("exception02")
    
  28. 
    
  29.     @setup(
    
  30.         {
    
  31.             "exception03": "{% extends 'inheritance01' %}"
    
  32.             "{% block first %}2{% endblock %}{% extends 'inheritance16' %}"
    
  33.         },
    
  34.         inheritance_templates,
    
  35.     )
    
  36.     def test_exception03(self):
    
  37.         """
    
  38.         Raise exception for extra {% extends %} tags
    
  39.         """
    
  40.         with self.assertRaises(TemplateSyntaxError):
    
  41.             self.engine.get_template("exception03")
    
  42. 
    
  43.     @setup(
    
  44.         {
    
  45.             "exception04": (
    
  46.                 "{% extends 'inheritance17' %}{% block first %}{% echo 400 %}5678"
    
  47.                 "{% endblock %}"
    
  48.             )
    
  49.         },
    
  50.         inheritance_templates,
    
  51.     )
    
  52.     def test_exception04(self):
    
  53.         """
    
  54.         Raise exception for custom tags used in child with {% load %} tag in
    
  55.         parent, not in child
    
  56.         """
    
  57.         with self.assertRaises(TemplateSyntaxError):
    
  58.             self.engine.get_template("exception04")
    
  59. 
    
  60.     @setup({"exception05": "{% block first %}{{ block.super }}{% endblock %}"})
    
  61.     def test_exception05(self):
    
  62.         """
    
  63.         Raise exception for block.super used in base template
    
  64.         """
    
  65.         with self.assertRaises(TemplateSyntaxError):
    
  66.             self.engine.render_to_string("exception05")