Beispiel #1
0
    def test_text_renders_correctly_inside_tags(self):
        test_str = "Testing"
        self.assertEqual(
            HtmlTag([],
                test_str
            ).render(),
            f"<htmltag>{test_str}</htmltag>"
        )

        self.assertEqual(
            Div([],
                test_str,
                test_str
            ).render(),
            f"<div>{test_str}{test_str}</div>"
        )

        self.assertEqual(
            Div([],
                test_str,
                A(),
                test_str
            ).render(),
            f"<div>{test_str}<a></a>{test_str}</div>"
        )
Beispiel #2
0
    def test_pretty_render(self):
        def build_html_text(nesting_level, current_level=1):
            if current_level>nesting_level:
                return

            html_text = ''
            html_text += "  "*current_level + "<htmltag>"

            result = build_html_text(nesting_level, current_level+1)
            if result:
                html_text += "\n" + result
                html_text += "\n" + "  "*current_level + "</htmltag>\n"
            else:
                html_text += "</htmltag>\n"

            html_text += "  "*current_level + "<htmltag></htmltag>\n"
            html_text += "  "*current_level + "<selfclosinghtmltag/>\n"
            html_text += "  "*current_level + f"level {current_level}"

            return html_text

        root_element = Html()
        current_element = root_element

        for i in range(1,10):
            inner_div = HtmlTag()

            current_element.inner_html = [
                inner_div,
                HtmlTag(),
                SelfClosingHtmlTag(),
                f"level {i}"
            ]

            self.assertEqual(
                f"<!DOCTYPE html>\n<html>\n{build_html_text(nesting_level=i)}\n</html>\n",
                root_element.render(pretty=True, doctype=True),
            )

            current_element = inner_div
Beispiel #3
0
 def setUp(self):
     self.not_self_closing_tags = filter(lambda tag: tag is not SelfClosingHtmlTag, HtmlTag.__subclasses__())
     self.self_closing_tags = SelfClosingHtmlTag.__subclasses__()
Beispiel #4
0
 def test_render_with_doctype_option(self):
     self.assertEqual("<!DOCTYPE html><htmltag></htmltag>", HtmlTag().render(doctype=True))
     self.assertEqual("<!DOCTYPE html><selfclosinghtmltag/>", SelfClosingHtmlTag().render(doctype=True))
Beispiel #5
0
 def test_raise_error_when_invalid_type_is_provided(self):
     with self.assertRaises(HtmlBuildError):
         HtmlTag(["invalid_attribute"])
     with self.assertRaises(HtmlBuildError):
         HtmlTag([HtmlTag])
Beispiel #6
0
 def test_html_tag_params_must_be_an_html_tag_or_str_instance(self):
     HtmlTag([], Div())
     HtmlTag([], "Test")
     with self.assertRaises(HtmlBuildError):
         HtmlTag([], Div)
Beispiel #7
0
 def test_render_style_attribute_from_named_params(self):
     self.assertEqual(
         HtmlTag([InlineStyle(custom_param1='test', custom_param2='test')]).render(),
         f"<htmltag style='custom-param1: test; custom-param2: test'></htmltag>"
     )
Beispiel #8
0
 def test_render_data_attribute(self):
     self.assertEqual(
         HtmlTag([Data_("test-value", "Testing")]).render(),
         "<htmltag data-test-value='Testing'></htmltag>"
     )
Beispiel #9
0
 def test_render_style_attribute_from_value_str(self):
     self.assertEqual(
         HtmlTag([InlineStyle("custom-param1: test; custom-param2: test")]).render(),
         f"<htmltag style='custom-param1: test; custom-param2: test'></htmltag>"
     )
Beispiel #10
0
 def setUp(self):
     self.all_attributes = HtmlTagAttribute.__subclasses__()
     self.all_tags = HtmlTag.__subclasses__()
Beispiel #11
0
 def test_element_types(self):
     tag: HtmlTag = HtmlTag()
     self.assertEquals(tag.times(2), [tag, tag])
Beispiel #12
0
 def test_returned_list_length(self):
     self.assertEquals(len(HtmlTag().times(10)), 10)
Beispiel #13
0
 def test_returns_list(self):
     self.assertIsInstance(HtmlTag().times(1), list)