コード例 #1
0
ファイル: test_links.py プロジェクト: mwilliamson/mash
def test_tree_to_html_converts_tree_to_nested_lists():
    tree = {
        "url": "/", "label": "zwobble.org",
        "children": [
            {
                "url": "/projects/", "label": "Projects",
                "children": [
                    {"url": "/projects/funk/", "label": "Funk"},
                    {"url": "/projects/zuice/", "label": "Zuice"}
                ]
            },
            {"url": "/blog/", "label": "Blog"}
        ]
    }
    expected_tree_html =\
"""<a href="/">zwobble.org</a>
<ul>
<li>
<a href="/projects/">Projects</a>
<ul>
<li>
<a href="/projects/funk/">Funk</a>
</li>
<li>
<a href="/projects/zuice/">Zuice</a>
</li>
</ul>
</li>
<li>
<a href="/blog/">Blog</a>
</li>
</ul>"""
    assert_equals(expected_tree_html, tree_to_html(tree))
コード例 #2
0
ファイル: test_links.py プロジェクト: mwilliamson/mash
def test_tree_to_html_does_not_create_link_for_root_if_it_has_no_url():
    tree = {
        "children": [
            {"url": "/projects/", "label": "Projects"},
            {"url": "/blog/", "label": "Blog"}
        ]
    }
    expected_tree_html =\
"""<ul>
<li>
<a href="/projects/">Projects</a>
</li>
<li>
<a href="/blog/">Blog</a>
</li>
</ul>"""
    assert_equals(expected_tree_html, tree_to_html(tree))
コード例 #3
0
ファイル: test_links.py プロジェクト: mwilliamson/mash
def test_tree_to_html_escapes_labels():
    assert_equals('<a href="/">P &lt;&gt; NP</a>', tree_to_html({"url": "/", "label": "P <> NP"}))
コード例 #4
0
ファイル: test_links.py プロジェクト: mwilliamson/mash
def test_tree_to_html_escapes_urls():
    assert_equals('<a href="http://www.example.com/src?project=funk&amp;repo=master">Source</a>',
                  tree_to_html({"url": "http://www.example.com/src?project=funk&repo=master", "label": "Source"}))
コード例 #5
0
ファイル: test_links.py プロジェクト: mwilliamson/mash
def test_tree_to_html_converts_tree_with_no_children_to_its_name_only():
    assert_equals('<a href="/">zwobble.org</a>', tree_to_html({"url": "/", "label": "zwobble.org"}))