Exemple #1
0
def test_pruning_links_leaves_only_direct_children_of_elements_on_current_path():
    tree = {
        "url": "/",
        "children": [
            {
                "url": "/projects/",
                "children": [
                    {
                        "url": "/projects/funk/",
                        "children": [
                            {"url": "/projects/funk/docs/"},
                            {"url": "/projects/funk/licence/"}
                        ]
                    },
                    {
                        "url": "/projects/zuice/",
                        "children": [
                            {"url": "/projects/zuice/docs/"},
                            {"url": "/projects/zuice/licence/"}
                        ]
                    }
                ]
            },
            {
                "url": "/blog/",
                "children": [
                    {"url": "/blog/archives/"},
                    {"url": "/blog/feed/"}
                ]
            }
        ]
    }
    
    prune(tree, "/projects/")
    expected_pruned_tree = {
        "url": "/",
        "children": [
            {
                "url": "/projects/",
                "children": [
                    {
                        "url": "/projects/funk/",
                    },
                    {
                        "url": "/projects/zuice/",
                    }
                ]
            },
            {
                "url": "/blog/",
            }
        ]
    }
    assert_equals(tree, expected_pruned_tree)
Exemple #2
0
def test_pruning_links_does_not_require_root_to_have_url():
    tree = {
        "children": [
            {
                "url": "/projects/",
                "children": [
                    {"url": "/projects/funk/"}
                ]
            },
            {"url": "/blog/"}
        ]
    }
    
    prune(tree, "/projects/hebe/")
    expected_pruned_tree = {
        "children": [
            {"url": "/projects/"},
            {"url": "/blog/"}
        ]
    }
    assert_equals(tree, expected_pruned_tree)
Exemple #3
0
def test_pruning_links_leaves_only_root_and_its_children_if_path_is_not_found():
    tree = {
        "url": "/",
        "children": [
            {
                "url": "/projects/",
                "children": [
                    {"url": "/projects/funk/"},
                    {"url": "/projects/zuice/"}
                ]
            },
            {"url": "/blog/"}
        ]
    }
    
    prune(tree, "/projects/hebe/")
    expected_pruned_tree = {
        "url": "/",
        "children": [
            {"url": "/projects/"},
            {"url": "/blog/"}
        ]
    }
    assert_equals(tree, expected_pruned_tree)