def test_extends_found_twice_raises_error(self):         
     html = stemp('''{% extends $location/template_test_single_section.html %}
     {% extends $location/template_test_single_section.html %}
     ''').substitute(var = self.header)
     template = Template(html, self.working_templates)
     with self.assertRaises(SyntaxError):
         template.sections
 def test_template_extension_from_remote_directory_not_found_raises_error(self):
     html = stemp('''
     {% extends $location/template_test_single_section.html %}
     ''')
     h = html.substitute(location = self.working_templates)
     template = Template(h, self.nonworking_templates)
     self.assertCountEqual(3, len(template.sections))
     self.assertCountEqual(1, len(template.dependency))
     self.assertListEqual(template.dependency, self.working_templates +"/template_test_single_section.html")
 def test_block_inheritance_block_not_found_raises_error(self):         
     html = stemp('''
     {% extends $location/template_test_single_section.html %}
     {% block header inherits %}
     $newhtml
     {% endblock header %}
     ''')
     h = html.substitute(location = self.working_templates, newhtml = "<link rel='author' title='Test' href='#'>")
     template = Template(h, self.working_templates)
     with self.assertRaises(SyntaxError):
         template.sections
 def test_in_childblock_endblock_missing_ending_brace_found_raises_error(self):         
     html = stemp('''
     {% extends $location/template_test_single_section.html %}
     {% block header %}
     {% block css %}
     {% endblock css %
     {% endblock header %}
     ''')
     html = html.substitute(location = self.working_templates)
     template = Template(html, self.working_templates)
     with self.assertRaises(SyntaxError):
         template.sections
 def test_nested_block_edit_without_parent_block_defined_in_parent_raises_error(self):  
     html = stemp('''
     {% extends $location/template_test_single_section.html %}
     {% block css %}
     {% endblock css %}
     <link rel='author' title='Test' href='#'>
     {% endblock header %}
     ''')
     h = html.substitute(location = self.working_templates)
     template = Template(h, self.working_templates)
     with self.assertRaises(KeyError):
         template.sections    
 def test_block_keepnested_with_parent_tag_raises_error(self):  
     html = stemp('''
     {% extends $location/template_test_single_section_with_nested.html %}
     {% block header keepnested%}
     {parent}
     <link rel='author' title='Test' href='#'>
     {% endblock header %}
     ''')
     h = html.substitute(location = self.working_templates)
     template = Template(h, self.working_templates)
     with self.assertRaises(SyntaxError):
         template.sections   
Пример #7
0
    def test_template_creation(self):
        html = stemp('''<!DOCTYPE html>
<html>
    {% block header %}
    <head>
    $var
    </head>
    {% endblock header %}
    <body>
    </body>
</html>''').substitute(var=self.header)
        template = Template(html, self.working_templates)
        self.assertMultiLineEqual(template.html, html)
    def test_startblock_without_endblock_found_raises_error(self):
        html = stemp('''<!DOCTYPE html>
<html>
    {% block header %}
    <head>
    $var
    </head>
    <body>
    </body>
</html>''').substitute(var=self.header)
        template = Template(html, self.working_templates)
        with self.assertRaises(KeyError):
            template.sections
 def test_startblock_additional_words_found_not_allowed_raises_error(self):         
     html = stemp('''
     {% extends $location/template_test_single_section.html %}
     {% block header $word %}
     <link rel='author' title='Test' href='#'>
     {% endblock header %}
     ''')
     for word in self.not_allowed_additional_words:
         h = html.substitute(location = self.working_templates, word = word)
         with self.subTest():
             template = Template(h, self.working_templates)
             with self.assertRaises(SyntaxError):
                 template.sections
Пример #10
0
 def test_block_inheritance_inherits_found(self):
     html = stemp('''
     {% extends $location/template_test_single_section.html %}
     {% block header inherits %}
     <link rel='author' title='Test' href='#'>
     {% endblock header %}
     ''')
     h = html.substitute(location=self.working_templates)
     template = Template(h, self.working_templates)
     self.assertCountEqual(3, len(template.sections))
     self.assertCountEqual(1, len(template.dependency))
     self.assertMultiLineEqual(template.dependency,
                               "/template_test_single_section.html")
 def test_same_section_key_defined_twice_raises_error(self):
     html = stemp('''
     {% extends $location/template_test_single_section.html %}
     {% block header %}
         {% block css %}
         {% endblock css %}
     {% endblock header %}
     {% block css %}
     {% endblock css %}
     ''')
     html = html.substitute(location = self.working_templates)
     template = Template(html, self.working_templates)
     with self.assertRaises(KeyError):
         template.sections
    def test_in_childblock_endblock_without_startblock_found_raises_error(self):
        html = stemp('''
        {% extends $location/template_test_single_section.html %}
        {% block header %}

        {% endblock css %}
        {% endblock header %}
        <link rel='author' title='Test' href='#'>
        {% endblock header %}
        ''')
        html = html.substitute(location = self.working_templates)
        template = Template(html, self.working_templates)
        with self.assertRaises(SyntaxError):
            template.sections
    def test_startblock_missing_second_modulo_found_raises_error(self):
        html = stemp('''<!DOCTYPE html>
<html>
    {% block header }
    <head>
    $var
    </head>
    {% endblock header %}
    <body>
    </body>
</html>''').substitute(var=self.header)
        template = Template(html, self.working_templates)
        with self.assertRaises(SyntaxError):
            template.sections
    def test_endblock_block_spelled_wrong_found_raises_error(self):
        html = stemp('''<!DOCTYPE html>
<html>
    {% block header %}
    <head>
    $var
    </head>
    {% endlock header %}
    <body>
    </body>
</html>''').substitute(var=self.header)
        template = Template(html, self.working_templates)
        with self.assertRaises(SyntaxError):
            template.sections
    def test_same_section_key_defined_twice_raises_error(self):
        html = stemp('''<!DOCTYPE html>
<html>
    {% block header %}
    <head>
    $var
    </head>
    {% endblock header %}
    {% block header %}
    <body>
    </body>
</html>''').substitute(var=self.header)
        template = Template(html, self.working_templates)
        with self.assertRaises(KeyError):
            template.sections
Пример #16
0
 def test_block_keepnested_parent_html_removed(self):
     html = stemp('''
     {% extends $location/template_test_single_section_with_nested.html %}
     {% block header keepnested %}
     <link rel='author' title='Test' href='#'>
     {% endblock header %}
     ''')
     h = html.substitute(location=self.working_templates)
     template = Template(h, self.working_templates)
     self.assertCountEqual(4, len(template.sections))
     self.assertCountEqual(1, len(template.dependency))
     self.assertMultiLineEqual(
         template.sections["header"]["html"],
         "<link rel='author' title='Test' href='#'>{children}"
     )  #a template keeps track of the html it has by linking the html of another template by its block name
     self.assertMultiLineEqual(template.dependency,
                               "/template_test_single_section.html")
Пример #17
0
 def test_block_inherit_keeps_html(self):
     html = stemp('''
     {% extends $location/template_test_single_section_with_nested.html %}
     {% block header inherits %}
     <link rel='author' title='Test' href='#'>
     {% endblock header %}
     ''')
     h = html.substitute(location=self.working_templates)
     template = Template(h, self.working_templates)
     self.assertCountEqual(4, len(template.sections))
     self.assertCountEqual(1, len(template.dependency))
     self.assertMultiLineEqual(
         template.sections["header"]["html"],
         "{parent}<link rel='author' title='Test' href='#'>"
     )  #a template keeps track of the html in the parent by marking parent
     self.assertMultiLineEqual(template.dependency,
                               "/template_test_single_section.html")
Пример #18
0
    def test_section_creation_maintains_order(self):
        html = stemp('''<!DOCTYPE html>
<html>
    {% block header %}
    <head>
    $var
    </head>
    {% endblock header %}
    {% block end %}
    {% endblock end %}
    <body>
    </body>
</html>''').substitute(var=self.header)
        template = Template(html, self.working_templates)
        self.assertEqual(4, len(template.sections))
        self.assertListEqual(['parent', 'header', 'end', 'foot'],
                             list(template.sections.keys()))
Пример #19
0
    def test_template_section_creation(self):
        html = stemp('''<!DOCTYPE html>
<html>
    {% block header %}
    <head>
    $var
    </head>
    {% endblock header %}
    <body>
    </body>
</html>''').substitute(var=self.header)
        template = Template(html, self.working_templates)
        self.assertEqual(3, len(template.sections))
        self.assertEqual(
            template.sections["header"],
            r"<head><meta charset=\"ISO-8859-1\"><title>Wilkins</title><link href=\"https://edge.fscdn.org/assets/docs/fs_logo_favicon.ico\" rel=\"icon\" type=\"image/x-icon\" /><!--<link href=\"http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap.min.css\" rel=\"stylesheet\" media=\"screen\">--><link href=\"/static/css/bootstrap.min.css\" rel=\"stylesheet\" media=\"screen\"><!--<link href='https://edge.fscdn.org/assets/css/responsive-166fbb8fd4a3f5207a500bdf6c2d9186.css' rel='stylesheet' media='screen'>--><link href='/static/css/responsive-166fbb8fd4a3f5207a500bdf6c2d9186.css' rel='stylesheet' media='screen'> <!--<link href='https://edge.fscdn.org/assets/css/layout/theme-engage-8e8aed919ce18a2f4b2a470bfc58b928.css' rel='stylesheet' media='screen'>--><link href='/static/css/theme-engage-8e8aed919ce18a2f4b2a470bfc58b928.css' rel='stylesheet' media='screen'><style type=\"text/css\">#global-engage-header{padding-top: 25px;}h1{padding-top:.5em;padding-bottom:0;margin-bottom:0;}h2{font-size:1.5em;padding-bottom:0;margin-bottom:0;}</style></head>"
        )
    def test_startblock_additional_words_found_not_allowed_without_extension_raises_error(self):         
        html = stemp('''<!DOCTYPE html>
<html>
    {% block header $word%}
    <head>
    $var
    </head>
    {% endblock header end %}
    <body>
    </body>
</html>''')
        for word in self.not_allowed_additional_words:
            h = html.substitute(word = word, var = self.header)
            with self.subTest():
                template = Template(h, self.working_templates)
                with self.assertRaises(ImportError):
                    template.sections