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))
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))
def test_tree_to_html_escapes_labels(): assert_equals('<a href="/">P <> NP</a>', tree_to_html({"url": "/", "label": "P <> NP"}))
def test_tree_to_html_escapes_urls(): assert_equals('<a href="http://www.example.com/src?project=funk&repo=master">Source</a>', tree_to_html({"url": "http://www.example.com/src?project=funk&repo=master", "label": "Source"}))
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"}))