Exemple #1
0
def test_version_pids_create(app, db):

    # Create a child, initialize the Versioning API and create a parent
    assert PersistentIdentifier.query.count() == 0
    # Create a child
    h1v1 = PersistentIdentifier.create('recid', '12345', object_type='rec',
                                       status=PIDStatus.REGISTERED)
    assert PersistentIdentifier.query.count() == 1
    pv = PIDVersioning(child=h1v1)
    # Create a parent
    pv.create_parent('12345.parent')
    assert PersistentIdentifier.query.count() == 2
    assert pv.parent.get_redirect() == h1v1
    assert pv.parent.status == PIDStatus.REDIRECTED
    # Make sure 'pid_type', 'object_type' and 'status' are inherited from child
    assert pv.parent.pid_type == pv.child.pid_type
    assert pv.parent.object_type == pv.child.object_type

    pr = PIDRelation.query.one()
    assert pr.child == h1v1
    assert pr.parent == pv.parent

    VERSION = resolve_relation_type_config('version').id
    assert pr.relation_type == VERSION
    assert pr.index == 0
def nested_pids_and_relations(app, db):
    """Fixture for a nested PIDs and the expected serialized relations."""
    # Create some PIDs and connect them into different nested PID relations
    pids = {}
    for idx in range(1, 12):
        pid_value = str(idx)
        p = PersistentIdentifier.create('recid',
                                        pid_value,
                                        object_type='rec',
                                        status=PIDStatus.REGISTERED)
        pids[idx] = p

    VERSION = resolve_relation_type_config('version').id

    #    1  (Version)
    #  / | \
    # 2  3 4
    PIDRelation.create(pids[1], pids[2], VERSION, 0)
    PIDRelation.create(pids[1], pids[3], VERSION, 1)
    PIDRelation.create(pids[1], pids[4], VERSION, 2)

    # Define the expected PID relation tree for of the PIDs
    expected_relations = {}
    expected_relations[4] = {
        u'relations': {
            'version': [{
                u'children': [{
                    u'pid_type': u'recid',
                    u'pid_value': u'2'
                }, {
                    u'pid_type': u'recid',
                    u'pid_value': u'3'
                }, {
                    u'pid_type': u'recid',
                    u'pid_value': u'4'
                }],
                u'index':
                2,
                u'is_child':
                True,
                u'previous': {
                    'pid_type': 'recid',
                    'pid_value': '3'
                },
                u'next':
                None,
                u'is_last':
                True,
                u'is_parent':
                False,
                u'parent': {
                    u'pid_type': u'recid',
                    u'pid_value': u'1'
                },
                u'type':
                'version'
            }],
        }
    }
    return pids, expected_relations
Exemple #3
0
def test_record_draft(app, db):
    """Test RecordDraft API."""

    assert PersistentIdentifier.query.count() == 0
    assert PIDRelation.query.count() == 0

    d1 = PersistentIdentifier.create('depid', '1', object_type='rec')
    r1 = PersistentIdentifier.create('recid', '1', object_type='rec')
    assert PersistentIdentifier.query.count() == 2

    RecordDraft.link(recid=r1, depid=d1)
    assert PIDRelation.query.count() == 1

    pr = PIDRelation.query.one()
    RECORD_DRAFT = resolve_relation_type_config('record_draft').id
    assert pr.relation_type == RECORD_DRAFT
    assert pr.index is None
    assert pr.parent == r1
    assert pr.child == d1

    d2 = PersistentIdentifier.create('depid', '2', object_type='rec')
    r2 = PersistentIdentifier.create('recid', '2', object_type='rec')

    with pytest.raises(Exception) as excinfo:
        RecordDraft.link(recid=r1, depid=d2)
    assert 'already has a depid as a draft' in str(excinfo.value)

    with pytest.raises(Exception) as excinfo:
        RecordDraft.link(recid=r2, depid=d1)
    assert 'already is a draft of a recid' in str(excinfo.value)
def pids(app, db):
    """Test PIDs fixture."""
    # TODO: Head PIDs do not have redirects as they are created outside API
    h1 = PersistentIdentifier.create('recid',
                                     'foobar',
                                     object_type='rec',
                                     status=PIDStatus.REGISTERED)
    h1v1 = PersistentIdentifier.create('recid', 'foobar.v1', object_type='rec')
    h1v2 = PersistentIdentifier.create('recid', 'foobar.v2', object_type='rec')
    h1v3 = PersistentIdentifier.create('recid', 'foobar.v3', object_type='rec')

    ORDERED = resolve_relation_type_config('ordered').id
    UNORDERED = resolve_relation_type_config('unordered').id
    PIDRelation.create(h1, h1v1, ORDERED, 0)
    PIDRelation.create(h1, h1v2, ORDERED, 1)
    PIDRelation.create(h1, h1v3, ORDERED, 2)
    h1.redirect(h1v3)

    h2 = PersistentIdentifier.create('recid',
                                     'spam',
                                     object_type='rec',
                                     status=PIDStatus.REGISTERED)
    h2v1 = PersistentIdentifier.create('recid', 'spam.v1')
    PIDRelation.create(h2, h2v1, ORDERED, 0)
    h2.redirect(h2v1)

    c1 = PersistentIdentifier.create('recid', 'bazbar')
    c1r1 = PersistentIdentifier.create('recid', 'resource1')
    c1r2 = PersistentIdentifier.create('recid', 'resource2')

    pid1 = PersistentIdentifier.create('recid', 'eggs')
    PIDRelation.create(c1, c1r1, UNORDERED, None)
    PIDRelation.create(c1, c1r2, UNORDERED, None)
    return {
        'h1': h1,
        'h1v1': h1v1,
        'h1v2': h1v2,
        'h1v3': h1v3,
        'h2': h2,
        'h2v1': h2v1,
        'c1': c1,
        'c1r1': c1r1,
        'c1r2': c1r2,
        'pid1': pid1,
    }
Exemple #5
0
def index():
    relation_id = resolve_relation_type_config('version').id
    heads = (
        PersistentIdentifier.query
        .join(
            PIDRelation,
            PIDRelation.parent_id == PersistentIdentifier.id)
        .filter(
            PIDRelation.relation_type == relation_id)
        .distinct())
    return render_template('index.html', heads=heads)
def nested_pids_and_relations(app, db):
    """Fixture for a nested PIDs and the expected serialized relations."""
    # Create some PIDs and connect them into different nested PID relations
    pids = {}
    for idx in range(1, 12):
        pid_value = str(idx)
        p = PersistentIdentifier.create('recid',
                                        pid_value,
                                        object_type='rec',
                                        status=PIDStatus.REGISTERED)
        pids[idx] = p

    ORDERED = resolve_relation_type_config('ordered').id
    UNORDERED = resolve_relation_type_config('unordered').id
    VERSION = resolve_relation_type_config('version').id

    #    1  (Version)
    #  / | \
    # 2  3 4
    PIDRelation.create(pids[1], pids[2], VERSION, 0)
    PIDRelation.create(pids[1], pids[3], VERSION, 1)
    PIDRelation.create(pids[1], pids[4], VERSION, 2)

    #    5  (Ordered)
    #  / | \
    # 6  4 7
    PIDRelation.create(pids[5], pids[6], ORDERED, 0)
    PIDRelation.create(pids[5], pids[4], ORDERED, 1)
    PIDRelation.create(pids[5], pids[7], ORDERED, 2)

    #    4  (Ordered)
    #  / |
    # 8  9
    PIDRelation.create(pids[4], pids[8], ORDERED, 0)
    PIDRelation.create(pids[4], pids[9], ORDERED, 1)

    #   10  (Unordered)
    #  / |
    # 4  11
    PIDRelation.create(pids[10], pids[4], UNORDERED, None)
    PIDRelation.create(pids[10], pids[11], UNORDERED, None)

    # Define the expected PID relation tree for of the PIDs
    expected_relations = {}
    expected_relations[4] = {
        'relations': {
            'version': [{
                'children': [{
                    'pid_type': 'recid',
                    'pid_value': '2'
                }, {
                    'pid_type': 'recid',
                    'pid_value': '3'
                }, {
                    'pid_type': 'recid',
                    'pid_value': '4'
                }],
                'is_child':
                True,
                'index':
                2,
                'previous': {
                    'pid_type': 'recid',
                    'pid_value': '3'
                },
                'next':
                None,
                'is_last':
                True,
                'is_ordered':
                True,
                'is_parent':
                False,
                'parent': {
                    'pid_type': 'recid',
                    'pid_value': '1'
                },
                'type':
                'version'
            }],
            'ordered': [{
                'children': [{
                    'pid_type': 'recid',
                    'pid_value': '6'
                }, {
                    'pid_type': 'recid',
                    'pid_value': '4'
                }, {
                    'pid_type': 'recid',
                    'pid_value': '7'
                }],
                'is_child':
                True,
                'index':
                1,
                'previous': {
                    'pid_type': 'recid',
                    'pid_value': '6'
                },
                'next': {
                    'pid_type': 'recid',
                    'pid_value': '7'
                },
                'is_last':
                False,
                'is_ordered':
                True,
                'is_parent':
                False,
                'parent': {
                    'pid_type': 'recid',
                    'pid_value': '5'
                },
                'type':
                'ordered'
            }, {
                'children': [{
                    'pid_type': 'recid',
                    'pid_value': '8'
                }, {
                    'pid_type': 'recid',
                    'pid_value': '9'
                }],
                'is_child':
                False,
                'index':
                None,
                'previous':
                None,
                'next':
                None,
                'is_last':
                None,
                'is_ordered':
                True,
                'is_parent':
                True,
                'parent': {
                    'pid_type': 'recid',
                    'pid_value': '4'
                },
                'type':
                'ordered'
            }],
            'unordered': [
                {
                    'children': [{
                        'pid_type': 'recid',
                        'pid_value': '4'
                    }, {
                        'pid_type': 'recid',
                        'pid_value': '11'
                    }],
                    'is_child':
                    True,
                    'index':
                    None,
                    'previous':
                    None,
                    'next':
                    None,
                    'is_last':
                    False,
                    'is_ordered':
                    True,
                    'is_parent':
                    False,
                    'parent': {
                        'pid_type': 'recid',
                        'pid_value': '10'
                    },
                    'type':
                    'unordered'
                },
            ]
        }
    }
    return pids, expected_relations
def draft_relation(app, db):
    """Versioning relation."""
    return resolve_relation_type_config('record_draft')
def version_relation(app, db):
    """Versioning relation."""
    return resolve_relation_type_config('version')