Exemple #1
0
def test_insert_nodes_at_highest_position(cur, root):
    highest_position = find_highest_position(cur, root)
    node4 = insert_node(cur, root, position=None, auto_position=True)
    node5 = insert_node(cur, root, position=-1, auto_position=True)
    assert node4.position == highest_position + 1
    assert node5.position == highest_position + 2

    delete_node(cur, node4)
    delete_node(cur, node5)
def test_insert_nodes_at_highest_position(cur, root):
    highest_position = find_highest_position(cur, root)
    node4 = insert_node(cur, root, position=None, auto_position=True)
    node5 = insert_node(cur, root, position=-1, auto_position=True)
    assert node4.position == highest_position + 1
    assert node5.position == highest_position + 2

    delete_node(cur, node4)
    delete_node(cur, node5)
Exemple #3
0
def test_delete_node(cur, nd1, nd2_1, nd2_1_1, nd2_leaf):
    """
        Tree layout before delete:
        /
          - nd1
            - nd2-1
              - nd2-1-1
                - nd2-leaf
          - nd2
          - nd3

        Expected tree layout after move:
        /
          - nd1
            - nd2-1
          - nd2
          - nd3
    """
    delete_node(cur, nd2_1_1, auto_position=False)

    # Deleted node doesn't exist anymore
    with pytest.raises(ValueError):
        get_node(cur, nd2_1_1.id)

    # nd2-1 has no children and no descendants
    assert set(get_child_ids(cur, nd2_1)) == set()
    assert set(get_child_ids(cur, nd2_1_1)) == set()
    assert set(get_descendant_ids(cur, nd2_1)) == set()

    # nd1 just contains nd2-1
    assert set(get_child_ids(cur, nd1)) == {nd2_1.id}
    assert set(get_descendant_ids(cur, nd1)) == {nd2_1.id}

    # Ancestor and descendant sets of nd2-1-1 and nd2-leaf are empty
    # (or raise error in the future because they don't exist anymore)
    assert set(get_ancestor_ids(cur, nd2_1_1)) == set()
    assert set(get_ancestor_ids(cur, nd2_leaf)) == set()
    assert set(get_descendant_ids(cur, nd2_1_1)) == set()
    assert set(get_descendant_ids(cur, nd2_leaf)) == set()
Exemple #4
0
def test_delete_node(cur, nd1, nd2_1, nd2_1_1, nd2_leaf):
    """
        Tree layout before delete:
        /
          - nd1
            - nd2-1
              - nd2-1-1
                - nd2-leaf
          - nd2
          - nd3

        Expected tree layout after move:
        /
          - nd1
            - nd2-1
          - nd2
          - nd3
    """
    delete_node(cur, nd2_1_1, auto_position=False)

    # Deleted node doesn't exist anymore
    with pytest.raises(exceptions.NodeNotFound):
        get_node(cur, nd2_1_1.id)

    # nd2-1 has no children and no descendants
    assert set(get_child_ids(cur, nd2_1)) == set()
    assert set(get_child_ids(cur, nd2_1_1)) == set()
    assert set(get_descendant_ids(cur, nd2_1)) == set()

    # nd1 just contains nd2-1
    assert set(get_child_ids(cur, nd1)) == {nd2_1.id}
    assert set(get_descendant_ids(cur, nd1)) == {nd2_1.id}

    # Ancestor and descendant sets of nd2-1-1 and nd2-leaf are empty
    # (or raise error in the future because they don't exist anymore)
    assert set(get_ancestor_ids(cur, nd2_1_1)) == set()
    assert set(get_ancestor_ids(cur, nd2_leaf)) == set()
    assert set(get_descendant_ids(cur, nd2_1_1)) == set()
    assert set(get_descendant_ids(cur, nd2_leaf)) == set()
Exemple #5
0
def test_delete_node_shifts_positions(cur, root, nd1):
    delete_node(cur, nd1, auto_position=True)
    positions = map(lambda n: n.position, get_children(cur, root))
    assert list(positions) == [0, 1, 3]
Exemple #6
0
def test_delete_node_by_id(cur, nd1, nd2_1):
    delete_node(cur, nd2_1.id, auto_position=True)

    assert set(get_child_ids(cur, nd1)) == set()
Exemple #7
0
def test_insert_root_node_with_auto_position(cur):
    root = insert_node(cur, None, 'folder', auto_position=True)
    delete_node(cur, root)
Exemple #8
0
def test_delete_node_by_id(cur, nd1, nd2_1):
    delete_node(cur, nd2_1.id, auto_position=True)

    assert set(get_child_ids(cur, nd1)) == set()
Exemple #9
0
def test_insert_root_node_with_auto_position(cur):
    root = insert_node(cur, None, 'folder', auto_position=True)
    delete_node(cur, root)
def test_delete_node_shifts_positions(cur, root, nd1):
    delete_node(cur, nd1, auto_position=True)
    positions = map(lambda n: n.position, get_children(cur, root))
    assert list(positions) == [0, 1, 3]