示例#1
0
def test_text_input(register_builtin_html):
    with output_funnel.plugged():
        html.text_input('tralala')
        written_text = "".join(output_funnel.drain())
        assert compare_html(
            written_text,
            '<input style="" name="tralala" type="text" class="text" value=\'\' />'
        )

    with output_funnel.plugged():
        html.text_input('blabla', cssclass='blubb')
        written_text = "".join(output_funnel.drain())
        assert compare_html(
            written_text,
            '<input style="" name="tralala" type="text" class="blubb" value=\'\' />'
        )

    with output_funnel.plugged():
        html.text_input('blabla', autocomplete='yep')
        written_text = "".join(output_funnel.drain())
        assert compare_html(
            written_text,
            '<input style="" name="blabla" autocomplete="yep" type="text" class="text" value=\'\' />'
        )

    with output_funnel.plugged():
        html.text_input('blabla',
                        placeholder='placido',
                        data_world='welt',
                        data_max_labels=42)
        written_text = "".join(output_funnel.drain())
        assert compare_html(
            written_text,
            '<input style="" name="tralala" type="text" class="text" value=\'\' />'
        )
示例#2
0
def test_render_a(register_builtin_html):
    a = html.render_a("bla", href="blu", class_=["eee"], target="_blank")
    assert compare_html(a, '<a href="blu" target="_blank" class="eee">bla</a>')

    a = html.render_a("b<script>alert(1)</script>la",
                      href="b<script>alert(1)</script>lu",
                      class_=["eee"],
                      target="_blank")
    assert compare_html(
        a,
        '<a href="b&lt;script&gt;alert(1)&lt;/script&gt;lu" target="_blank" '
        'class="eee">b&lt;script&gt;alert(1)&lt;/script&gt;la</a>')
示例#3
0
def test_add_manual_link_anchor(module_wide_request_context, monkeypatch):
    monkeypatch.setattr(config.user, "language", lambda: "de")
    assert compare_html(
        html.render_help(u"[graphing#rrds|RRDs]"),
        HTML(
            u"<div style=\"display:none\" class=\"help\"><a href=\"https://docs.checkmk.de/master/de/graphing.html#rrds\" target=\"_blank\">RRDs</a></div>"
        ))
示例#4
0
def test_add_manual_link_localized(module_wide_request_context, monkeypatch):
    monkeypatch.setattr(config.user, "language", lambda: "de")
    assert compare_html(
        html.render_help(u"[introduction_docker|docker]"),
        HTML(
            u"<div style=\"display:none\" class=\"help\"><a href=\"https://docs.checkmk.com/master/de/introduction_docker.html\" target=\"_blank\">docker</a></div>"
        ))
示例#5
0
def test_add_manual_link(register_builtin_html):
    assert config.user.language is None
    assert compare_html(
        html.render_help(u"[introduction_docker|docker]"),
        HTML(
            u"<div style=\"display:none\" class=\"help\"><a href=\"https://docs.checkmk.com/master/en/introduction_docker.html\" target=\"_blank\">docker</a></div>"
        ))
示例#6
0
def test_render_help_html(register_builtin_html):
    assert html.have_help is False
    assert compare_html(
        html.render_help(HTML("<abc>")),
        HTML("<div style=\"display:none\" class=\"help\"><abc></div>"))
    # NOTE: This seems to be a mypy 0.780 bug.
    assert html.have_help is True  # type: ignore[comparison-overlap]
示例#7
0
def test_nesting_context(register_builtin_html):
    table_id = 0
    title = " TEST "

    with output_funnel.plugged():
        with table_element(table_id="%d" % table_id,
                           title=title,
                           searchable=False,
                           sortable=False) as table1:
            table1.row()
            table1.cell("A", "1")
            table1.cell("B", "")
            with table_element("%d" % (table_id + 1),
                               title + "2",
                               searchable=False,
                               sortable=False) as table2:
                table2.row()
                table2.cell("_", "+")
                table2.cell("|", "-")

        written_text = "".join(output_funnel.drain())
    assert compare_html(
        written_text, '''<h3 class="table">  TEST </h3>
                            <script type="text/javascript">\ncmk.utils.update_row_info(\'1 row\');\n</script>
                            <table class="data oddeven">
                            <tr>  <th>   A  </th>  <th>   B  </th> </tr>
                            <tr class="data even0">  <td>   1  </td>  <td>
                                <h3 class="table"> TEST 2</h3>
                                <script type="text/javascript">\ncmk.utils.update_row_info(\'1 row\');\n</script>
                                <table class="data oddeven">
                                <tr><th>_</th><th>|</th></tr>
                                <tr class="data even0"><td>+</td><td>-</td></tr>
                                </table>  </td>
                            </tr>
                            </table>'''), written_text
示例#8
0
def test_ABCHTMLGenerator(register_builtin_html):
    with output_funnel.plugged():

        with output_funnel.plugged():
            html.open_div()
            text = output_funnel.drain()
            assert text.rstrip('\n').rstrip(' ') == "<div>"

        with output_funnel.plugged():
            #html.open_div().write("test").close_div()
            html.open_div()
            html.write_text("test")
            html.close_div()
            assert compare_html(output_funnel.drain(), "<div>test</div>")

        with output_funnel.plugged():
            #html.open_table().open_tr().td("1").td("2").close_tr().close_table()
            html.open_table()
            html.open_tr()
            html.td("1")
            html.td("2")
            html.close_tr()
            html.close_table()
            assert compare_html(
                output_funnel.drain(),
                "<table><tr><td>1</td><td>2</td></tr></table>")

        with output_funnel.plugged():
            html.div("test", **{"</div>malicious_code<div>": "trends"})
            assert compare_html(
                output_funnel.drain(),
                "<div &lt;/div&gt;malicious_code&lt;div&gt;=trends>test</div>")

        a = u"\u2665"
        with output_funnel.plugged():
            assert html.render_a("test", href="www.test.case")
            html.render_a(u"test", href="www.test.case")
            html.render_a("test", href=u"www.test.case")
            html.render_a(u"test", href=u"www.test.case")
            try:
                assert html.render_a(u"test",
                                     href=str("www.test.case"),
                                     id_=str("something"),
                                     class_=str("test_%s") % a)
            except Exception as e:
                traceback.print_exc()
                print(e)
示例#9
0
def test_render_help_visible(module_wide_request_context,
                             register_builtin_html, monkeypatch):
    monkeypatch.setattr(config.LoggedInUser, "show_help",
                        property(lambda s: True))
    assert config.user.show_help is True
    assert compare_html(
        html.render_help(u"äbc"),
        HTML(u"<div style=\"display:block\" class=\"help\">äbc</div>"))
示例#10
0
def test_foldable_container(register_builtin_html) -> None:
    with output_funnel.plugged():
        with foldable_container(treename="name",
                                id_="id",
                                isopen=False,
                                title="Title") as is_open:
            assert is_open is False
        code = output_funnel.drain()
        assert compare_html(
            code, '''<div class="foldable closed"><b
onclick="cmk.foldable_container.toggle(&quot;name&quot;, &quot;id&quot;,
&quot;&quot;)" class="treeangle title">Title</b><img id="treeimg.name.id"
onclick="cmk.foldable_container.toggle(&quot;name&quot;, &quot;id&quot;,
&quot;&quot;)" src="themes/facelift/images/tree_closed.svg" class="treeangle
closed" /><br/><ul id="tree.name.id" style="padding-left: 15px; " class="treeangle
closed"></ul></div>''')
示例#11
0
def test_render_help_text(register_builtin_html):
    assert compare_html(
        html.render_help(u"äbc"),
        HTML(u"<div style=\"display:none\" class=\"help\">äbc</div>"))
示例#12
0
def test_exception_handling(register_builtin_html):
    try:
        raise Exception("Test")
    except Exception as e:
        assert compare_html(html.render_div(str(e)), "<div>%s</div>" % e)
示例#13
0
def test_multiclass_call(register_builtin_html):
    with output_funnel.plugged():
        html.div('', class_="1", css="3", cssclass="4", **{"class": "2"})
        written_text = "".join(output_funnel.drain())
    assert compare_html(written_text, "<div class=\"1 3 4 2\"></div>")