Esempio n. 1
0
def test_add_child_element_list():
    test_tag = TagFactory("test_tag")
    child_tag = TagFactory("div")
    child_list = []
    for x in range(3):
        child_list.append(child_tag)
    test_tag.add_child_element(child_list)
    assert (str(test_tag) == "<test_tag><div></div><div>" +
            "</div><div></div></test_tag>")
Esempio n. 2
0
def get_checkbox_component():
    checkbox_component = TagFactory(
        "div.form-check",
        (
            TagFactory("input.form-check-input", id="exampleCheck1"),
            TagFactory("label.form-check-label",
                       "Check me out",
                       four="exampleCheck1"),
        ),
    )

    return checkbox_component
Esempio n. 3
0
def get_password_component():
    password_component = TagFactory(
        "div.form-group",
        (
            TagFactory("label", "Password", four="exampleInputPassword1"),
            TagFactory("input.form-control",
                       id="exampleInputPassword1",
                       placeholder="Password"),
        ),
    )

    return password_component
Esempio n. 4
0
def example_form():
    form_component = TagFactory("form")
    form_component.add_child_element(get_email_component())
    form_component.add_child_element(get_password_component())
    form_component.add_child_element(get_checkbox_component())
    form_component.add_child_element(get_submit_button())
    return form_component
Esempio n. 5
0
def test_omitted_dash():
    test_tag = TagFactory("div",
                          "",
                          role="application",
                          ariadescribedby="info")
    assert (str(test_tag) == """<div role='application' """ +
            """aria-describedby='info'></div>""")
Esempio n. 6
0
def test_add_child_element_with_multiple_child_tags():
    test_tag = TagFactory("test_tag")
    test_tag.add_child_element([
        TagFactory(
            "div.container",
            TagFactory(
                "div1",
                TagFactory("div2", TagFactory("div3", TagFactory("div4")))),
        )
    ])
    assert (
        str(test_tag) == """<test_tag><div class='container'><div1><div2>""" +
        "<div3><div4></div4></div3></div2>" + "</div1></div></test_tag>")
Esempio n. 7
0
def get_body_component():
    body = TagFactory("body")
    body.add_child_element(
        TagFactory(
            "script",
            src="https://code.jquery.com/jquery-3.2.1.slim.min.js",
            integrity=
            "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN",
            crossorigin="anonymous",
        ),
        TagFactory(
            "script",
            src=
            "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js",
            integrity=
            "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q",
            crossorigin="anonymous",
        ),
        TagFactory(
            "script",
            src=
            "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js",
            integrity=
            "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl",
            crossorigin="anonymous",
        ),
    )

    return body
Esempio n. 8
0
def test_attributes():
    test_tag = TagFactory(
        "div",
        "I have an action and method attribute.",
        action="/action_page.php",
        method="get",
    )
    assert (
        str(test_tag) == """<div action='/action_page.php' method='get'>""" +
        "I have an action and method attribute.</div>")
Esempio n. 9
0
def get_email_component():
    email_component = TagFactory(
        "div.form-group",
        (
            TagFactory("label", "Email Address", four="exampleInputEmail1"),
            TagFactory(
                "input.form-control",
                id="exampleInputEmail1",
                ariadescribedby="emailHelp",
                placeholder="Enter email",
            ),
            TagFactory(
                "small.form-text.text-muted",
                "We'll never share your email with anyone else.",
                id="emailHelp",
            ),
        ),
    )

    return email_component
Esempio n. 10
0
def get_head_component():
    head = TagFactory("head")
    head.add_child_element(
        SingletonTag("meta", charset="utf-8"),
        SingletonTag(
            "meta",
            content="width=device-width, initial-scale=1, shrink-to-fit=no",
        ),
        SingletonTag(
            "link",
            href=
            "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css",
            integrity=
            "sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm",
            crossorigin="anonymous",
        ),
        TagFactory("title", "Hello, world!"),
    )

    return head
Esempio n. 11
0
def test_singleton_tag_as_child_element():
    a_tag = TagFactory("a",
                       SingletonTag("img", src="logo_w3s.gif"),
                       href="www.google.com")
    assert (str(a_tag) == """<a href='www.google.com'>""" +
            """<img src='logo_w3s.gif'></a>""")
Esempio n. 12
0
def test_pretty_str_with_html_tags():
    test_tag = TagFactory("div", TagFactory("div-2", ""))
    assert (test_tag.pretty_str(
        add_html_tags=True) == "<html>\n <head>\n </head>\n <body>\n  <div>\n"
            + "   <div-2>\n   </div-2>\n  </div>\n </body>\n</html>")
Esempio n. 13
0
def test_pretty_str():
    test_tag = TagFactory("div", TagFactory("div-2", ""))
    assert test_tag.pretty_str() == """<div>\n <div-2>\n </div-2>\n</div>"""
Esempio n. 14
0
def test_inner_html_tuple():
    assert (str(TagFactory("div.my-class", (TagFactory("div", "child tag"))))
            == """<div class='my-class'><div>child tag</div></div>""")
Esempio n. 15
0
def test_single_tagfactory_child():
    test_tag = TagFactory("div", TagFactory("div-2", ""))
    assert str(test_tag) == """<div><div-2></div-2></div>"""
Esempio n. 16
0
def test_multiple_classes():
    test_tag = TagFactory("div.col-10.col-lg-9.d-inline-block", "")
    assert (str(test_tag) == """<div class='col-10 col-lg-9 """ +
            """d-inline-block'></div>""")
Esempio n. 17
0
def test_for_attribute():
    test_tag = TagFactory("div.my-class", "inside the div", four="my-form")
    assert (str(test_tag) == """<div class='my-class\' """ +
            """for='my-form'>inside the div</div>""")
Esempio n. 18
0
def test_singleton_tag_add_with_child_element_list():
    body = TagFactory("body")
    body.add_child_element(SingletonTag("img"), SingletonTag("img1"))
    assert str(body) == "<body><img><img1></body>"
Esempio n. 19
0
def get_submit_button():
    button_component = TagFactory("button.btn.btn-primary",
                                  "Submit",
                                  type="submit")

    return button_component
Esempio n. 20
0
def test_add_child_element():
    test_tag = TagFactory("footer.footer")
    test_tag.add_child_element((TagFactory("div.container")))
    assert (str(test_tag) == """<footer class='footer'>""" +
            """<div class='container'></div></footer>""")
Esempio n. 21
0
def test_set_str_as_child_element_after_setting_child_tag():
    test_tag = TagFactory("test_tag", TagFactory("div"))
    test_tag.add_child_element("This is a test string.")
    assert str(test_tag) == "<test_tag>This is a test string.</test_tag>"
Esempio n. 22
0
def test_add_child_element_with_existing_child_element():
    test_tag = TagFactory("test_tag", TagFactory("div"))
    test_tag.add_child_element(TagFactory("child"))
    assert str(test_tag) == "<test_tag><div></div><child></child></test_tag>"
Esempio n. 23
0
def test_basic_tag():
    test_tag = TagFactory("div")
    assert str(test_tag) == "<div></div>"
Esempio n. 24
0
def test_singleton_tag_with_add_child_element_function():
    img_tag = SingletonTag("img", src="logo_w3s.gif")
    a_tag = TagFactory("a", href="www.google.com")
    a_tag.add_child_element(img_tag)
    assert (str(a_tag) == """<a href='www.google.com'>""" +
            """<img src='logo_w3s.gif'></a>""")
Esempio n. 25
0
def test_add_child_element_with_child_element():
    test_tag = TagFactory("test_tag")
    test_tag.add_child_element(TagFactory("div.container", TagFactory("div1")))
    assert (str(test_tag) == """<test_tag><div class='container'>""" +
            "<div1></div1></div></test_tag>")
Esempio n. 26
0
def example_base_html_page():
    html_page = TagFactory("html", lang="en")
    html_page.add_child_element(get_head_component())
    html_page.add_child_element(get_body_component())

    return html_page