コード例 #1
0
def test_versioning_insert_child(db, version_pids, build_pid):
    """Test PIDNodeVersioning.insert_child(...)."""
    new_pids = create_pids(3)
    parent_pid = build_pid(version_pids[0]['parent'])
    h1 = PIDNodeVersioning(parent_pid)
    # insert as first child
    h1.insert_child(new_pids[0], 0)
    version_pids[0]['children'].insert(0, new_pids[0])
    assert h1.children.ordered('asc').all() == \
        filter_pids(version_pids[0]['children'], PIDStatus.REGISTERED)

    # insert as last child. This should insert just before the draft
    version_pids[0]['children'].insert(h1.index(h1.draft_child), new_pids[1])
    h1.insert_child(new_pids[1], -1)
    # Check that the parent redirects to the added PID
    assert (version_pids[0]['parent'].get_redirect() == new_pids[1])
    # Register the draft so that it appears in the children
    h1.draft_child.register()
    h1.update_redirect()
    assert h1.children.ordered('asc').all() == \
        filter_pids(version_pids[0]['children'], PIDStatus.REGISTERED)

    # insert again but without a draft child. It should be inserted at the end.
    version_pids[0]['children'].append(new_pids[2])
    h1.insert_child(new_pids[2], -1)
    assert h1.children.ordered('asc').all() == \
        filter_pids(version_pids[0]['children'], PIDStatus.REGISTERED)

    reserved_pid = create_pids(1, status=PIDStatus.RESERVED)[0]

    # Check the exception raised when trying to insert a RESERVED PID
    with pytest.raises(PIDRelationConsistencyError):
        h1.insert_child(reserved_pid)
コード例 #2
0
def test_update_redirect(db, version_pids, build_pid):
    """Test PIDNodeVersioning.update_redirect()."""
    # Test update_redirect on a PID without any child
    parent_pids = create_pids(1, prefix='parent', status=PIDStatus.RESERVED)
    draft_pids = create_pids(2, prefix='draft', status=PIDStatus.RESERVED)
    parent = PIDNodeVersioning(build_pid(parent_pids[0]))
    parent.update_redirect()
    assert parent_pids[0].status == PIDStatus.RESERVED

    # Test that update_redirect remains reserved once it has a draft child
    parent.insert_draft_child(draft_pids[0])
    assert parent_pids[0].status == PIDStatus.RESERVED

    h1 = PIDNodeVersioning(build_pid(version_pids[0]['parent']))

    def test_redirect(expected_length, expected_redirect):
        filtered = filter_pids(version_pids[0]['children'],
                               status=PIDStatus.REGISTERED)
        assert len(filtered) == expected_length
        assert h1.children.ordered('asc').all() == filtered
        assert h1._resolved_pid.get_redirect() == expected_redirect

    # Test update_redirect when it already points to the last version
    last = h1.last_child
    draft = h1.draft_child
    h1.update_redirect()
    test_redirect(3, last)

    # Test update_redirect after publishing the draft
    h1.draft_child.register()
    h1.update_redirect()
    test_redirect(4, draft)

    # Test update_redirect after deleting the last version
    h1.last_child.delete()
    h1.update_redirect()
    test_redirect(3, last)

    # Test that if every version is deleted the HEAD pid is also deleted
    for pid in filter_pids(version_pids[0]['children'],
                           status=PIDStatus.REGISTERED):
        pid.delete()
    h1.update_redirect()
    test_redirect(0, last)

    # Test that an exception is raised if unsupported PIDStatus are used.
    version_pids[0]['children'][0].status = PIDStatus.NEW
    with pytest.raises(PIDRelationConsistencyError):
        h1.update_redirect()
コード例 #3
0
def test_record_draft(app, db, build_pid, recids):
    """Test RecordDraft API."""

    parent_pids = [PIDNodeDraft(pid) for pid in create_pids(2, 'parent')]
    draft_pids = create_pids(2, 'draft')

    # create a parent-draft relationship
    parent_pids[0].insert_child(draft_pids[0])

    assert parent_pids[0].children.all() == [draft_pids[0]]

    # try to create invalid additional parent-draft relationships
    with pytest.raises(PIDRelationConsistencyError):
        parent_pids[0].insert_child(draft_pids[1])
        parent_pids[1].insert_child(draft_pids[0])
コード例 #4
0
def test_node_max_children(db, version_relation, version_pids, build_pid,
                           recids):
    """Test the PIDNode max children attribute."""
    parent_pid = build_pid(version_pids[0]['parent'])
    ordered_parent_node = \
        PIDNode(parent_pid,
                version_relation,
                max_children=len(version_pids[0]['children']))
    child_pids = create_pids(1)

    with pytest.raises(PIDRelationConsistencyError):
        ordered_parent_node.insert_child(child_pids[0])
コード例 #5
0
def test_node_max_parents(db, version_relation, version_pids, build_pid,
                          recids):
    """Test the PIDNode max parents attribute."""
    parent_pid_1 = build_pid(version_pids[0]['parent'])
    parent_pid_2 = build_pid(version_pids[1]['parent'])
    ordered_parent_node_1 = PIDNode(parent_pid_1,
                                    version_relation,
                                    max_parents=1)
    ordered_parent_node_2 = PIDNode(parent_pid_2,
                                    version_relation,
                                    max_parents=1)
    child_pids = create_pids(1)

    ordered_parent_node_1.insert_child(child_pids[0])
    with pytest.raises(PIDRelationConsistencyError):
        ordered_parent_node_2.insert_child(child_pids[0])
コード例 #6
0
def test_ordered_node_insert(db, version_relation, version_pids, build_pid,
                             recids):
    """Test the PIDNodeOrdered insert method."""
    parent_pid = build_pid(version_pids[0]['parent'])
    ordered_parent_node = PIDNodeOrdered(parent_pid, version_relation)
    child_pids = create_pids(3)

    # c-c-c-c-c-x
    # inserting in the end
    ordered_parent_node.insert_child(child_pids[0], -1)
    version_pids[0]['children'].append(child_pids[0])
    assert_children_indices(ordered_parent_node, version_pids[0]['children'])

    # x-c-c-c-c-c-c
    # inserting in the beginning
    ordered_parent_node.insert_child(child_pids[1], 0)
    version_pids[0]['children'].insert(0, child_pids[1])
    assert_children_indices(ordered_parent_node, version_pids[0]['children'])

    # c-c-c-x-c-c-c-c
    # inserting in the middle
    ordered_parent_node.insert_child(child_pids[2], 3)
    version_pids[0]['children'].insert(3, child_pids[2])
    assert_children_indices(ordered_parent_node, version_pids[0]['children'])