Beispiel #1
0
def test_ordered_node_remove_without_reorder(db, version_relation,
                                             version_pids, build_pid, recids):
    """Test PIDNode.remove_child."""
    parent_pid = build_pid(version_pids[0]['parent'])
    ordered_parent_node = PIDNodeOrdered(parent_pid, version_relation)

    # c-c-c-c-c-x
    # remove the last child
    ordered_parent_node.remove_child(version_pids[0]['children'][-1],
                                     reorder=False)
    del version_pids[0]['children'][-1]
    assert_children_indices(ordered_parent_node, version_pids[0]['children'])

    # x-c-c-c-c
    # remove the first child
    ordered_parent_node.remove_child(version_pids[0]['children'][0],
                                     reorder=False)
    del version_pids[0]['children'][0]
    assert len(ordered_parent_node.children.all()) == \
        len(version_pids[0]['children'])
    for idx, child_pid in enumerate(version_pids[0]['children']):
        assert ordered_parent_node.index(child_pid) == idx + 1

    # c-x-c-c
    # remove the middle child
    ordered_parent_node.remove_child(version_pids[0]['children'][1],
                                     reorder=False)
    del version_pids[0]['children'][1]
    assert len(ordered_parent_node.children.all()) == \
        len(version_pids[0]['children'])
    expected = [1, 3, 4]
    for idx, child_pid in enumerate(version_pids[0]['children']):
        assert ordered_parent_node.index(child_pid) == expected[idx]
Beispiel #2
0
def test_ordered_node_index(db, version_relation, version_pids, build_pid,
                            recids):
    """Test the PIDNodeOrdered index method."""
    parent_pid = build_pid(version_pids[0]['parent'])
    ordered_parent_node = PIDNodeOrdered(parent_pid, version_relation)

    for idx, child_pid in enumerate(version_pids[0]['children']):
        assert ordered_parent_node.index(child_pid) == idx

    child_pid = build_pid(recids[str(PIDStatus.REGISTERED)])
    ordered_parent_node.insert_child(child_pid)
    assert ordered_parent_node.index(child_pid) == \
        len(version_pids[0]['children'])