Esempio n. 1
0
def test_text_input(request_context):
    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=\'\' />'
        )
Esempio n. 2
0
def test_HTMLWriter(request_context):
    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 = "\u2665"
        with output_funnel.plugged():
            assert HTMLWriter.render_a("test", href="www.test.case")
            HTMLWriter.render_a("test", href="www.test.case")
            HTMLWriter.render_a("test", href="www.test.case")
            HTMLWriter.render_a("test", href="www.test.case")
            try:
                assert HTMLWriter.render_a(
                    "test",
                    href=str("www.test.case"),
                    id_=str("something"),
                    class_=str("test_%s") % a,
                )
            except Exception as e:
                traceback.print_exc()
                print(e)
Esempio n. 3
0
def test_render_a(request_context):
    a = HTMLWriter.render_a("bla", href="blu", class_=["eee"], target="_blank")
    assert compare_html(a, '<a href="blu" target="_blank" class="eee">bla</a>')

    a = HTMLWriter.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>',
    )
Esempio n. 4
0
def test_render_help_html(request_context):
    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]
Esempio n. 5
0
def test_add_manual_link_anchor(request_context, monkeypatch):
    monkeypatch.setattr(user, "language", lambda: "de")
    assert compare_html(
        html.render_help("[graphing#rrds|RRDs]"),
        HTML(
            '<div style="display:none" class="help"><a href="https://docs.checkmk.de/master/de/graphing.html#rrds" target="_blank">RRDs</a></div>'
        ),
    )
Esempio n. 6
0
def test_add_manual_link_localized(request_context, monkeypatch):
    monkeypatch.setattr(user, "language", lambda: "de")
    assert compare_html(
        html.render_help("[intro_welcome|Welcome]"),
        HTML(
            '<div style="display:none" class="help"><a href="https://docs.checkmk.com/master/de/intro_welcome.html" target="_blank">Welcome</a></div>'
        ),
    )
Esempio n. 7
0
def test_add_manual_link(request_context):
    assert user.language is None
    assert compare_html(
        html.render_help("[intro_welcome|Welcome]"),
        HTML(
            '<div style="display:none" class="help"><a href="https://docs.checkmk.com/master/en/intro_welcome.html" target="_blank">Welcome</a></div>'
        ),
    )
def test_foldable_container(request_context) -> 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"><div
onclick="cmk.foldable_container.toggle(&quot;name&quot;, &quot;id&quot;, &quot;&quot;)"
class="foldable_header"><b class="treeangle title">Title</b><img id="treeimg.name.id"
src="themes/facelift/images/tree_closed.svg" class="treeangle closed" /></div><ul
id="tree.name.id" style="padding-left: 15px; " class="treeangle closed"></ul></div>""",
        )
Esempio n. 9
0
def test_nesting_context(request_context):
    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
Esempio n. 10
0
def test_render_help_visible(request_context, monkeypatch):
    monkeypatch.setattr(LoggedInUser, "show_help", property(lambda s: True))
    assert user.show_help is True
    assert compare_html(
        html.render_help("äbc"),
        HTML('<div style="display:block" class="help">äbc</div>'))
Esempio n. 11
0
def test_render_help_text(request_context):
    assert compare_html(
        html.render_help("äbc"),
        HTML('<div style="display:none" class="help">äbc</div>'))
Esempio n. 12
0
def test_exception_handling(request_context):
    try:
        raise Exception("Test")
    except Exception as e:
        assert compare_html(HTMLWriter.render_div(str(e)), "<div>%s</div>" % e)
Esempio n. 13
0
def test_multiclass_call(request_context):
    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>')