examples/app.py
def records():
    """Load test data fixture."""
    import uuid
    from invenio_records.api import Record
    from invenio_pidstore.models import PersistentIdentifier, PIDStatus

    # Record 1 - Live record
    with db.session.begin_nested():
        pid1 = PersistentIdentifier.create(
            'recid', '1', object_type='rec', object_uuid=rec1_uuid,
            status=PIDStatus.REGISTERED)
        Record.create({
            'title': 'Registered ',
            'authors': [
                {'name': 'Ellis Jonathan'},
                {'name': 'Higgs Peter'},
            ],
            'access': 'open',
            'keywords': ['CERN', 'higgs'],
        }, id_=rec1_uuid)

        PersistentIdentifier.create(
            'recid', '2', object_type='rec', object_uuid=rec2_uuid,
            status=PIDStatus.REGISTERED)
        Record.create({
            'title': 'Registered ',
            'authors': [
                {'name': 'Ellis Jonathan'},
                {'name': 'Higgs Peter'},
            ],
            'access': 'closed',
            'keywords': ['CERN', 'higgs'],
        }, id_=rec2_uuid)

        # Record 3 - Deleted PID with record
        rec3_uuid = uuid.uuid4()
        pid = PersistentIdentifier.create(
            'recid', '3', object_type='rec', object_uuid=rec3_uuid,
            status=PIDStatus.REGISTERED)
        pid.delete()
        Record.create({'title': 'Live '}, id_=rec3_uuid)

        # Record 4 - Deleted PID without a record
        PersistentIdentifier.create(
            'recid', '4', status=PIDStatus.DELETED)

        # Record 5 - Registered PID without a record
        PersistentIdentifier.create(
            'recid', '5', status=PIDStatus.REGISTERED)

        # Record 6 - Redirected PID
        pid = PersistentIdentifier.create(
            'recid', '6', status=PIDStatus.REGISTERED)
        pid.redirect(pid1)

        # Record 7 - Redirected non existing endpoint
        doi = PersistentIdentifier.create(
            'doi', '10.1234/foo', status=PIDStatus.REGISTERED)
        pid = PersistentIdentifier.create(
            'recid', '7', status=PIDStatus.REGISTERED)
        pid.redirect(doi)

        # Record 8 - Unregistered PID
        PersistentIdentifier.create(
            'recid', '8', status=PIDStatus.RESERVED)

    db.session.commit()
def records():
    """Load test data fixture."""
    import uuid
    from invenio_records.api import Record
    from invenio_pidstore.models import PersistentIdentifier, PIDStatus

    # Record 1 - Live record
    with db.session.begin_nested():
        pid1 = PersistentIdentifier.create(
            'recid', '1', object_type='rec', object_uuid=rec1_uuid,
            status=PIDStatus.REGISTERED)
        Record.create({
            'title': 'Registered ',
            'authors': [
                {'name': 'Ellis Jonathan'},
                {'name': 'Higgs Peter'},
            ],
            'access': 'open',
            'keywords': ['CERN', 'higgs'],
        }, id_=rec1_uuid)

        PersistentIdentifier.create(
            'recid', '2', object_type='rec', object_uuid=rec2_uuid,
            status=PIDStatus.REGISTERED)
        Record.create({
            'title': 'Registered ',
            'authors': [
                {'name': 'Ellis Jonathan'},
                {'name': 'Higgs Peter'},
            ],
            'access': 'closed',
            'keywords': ['CERN', 'higgs'],
        }, id_=rec2_uuid)

        # Record 3 - Deleted PID with record
        rec3_uuid = uuid.uuid4()
        pid = PersistentIdentifier.create(
            'recid', '3', object_type='rec', object_uuid=rec3_uuid,
            status=PIDStatus.REGISTERED)
        pid.delete()
        Record.create({'title': 'Live '}, id_=rec3_uuid)

        # Record 4 - Deleted PID without a record
        PersistentIdentifier.create(
            'recid', '4', status=PIDStatus.DELETED)

        # Record 5 - Registered PID without a record
        PersistentIdentifier.create(
            'recid', '5', status=PIDStatus.REGISTERED)

        # Record 6 - Redirected PID
        pid = PersistentIdentifier.create(
            'recid', '6', status=PIDStatus.REGISTERED)
        pid.redirect(pid1)

        # Record 7 - Redirected non existing endpoint
        doi = PersistentIdentifier.create(
            'doi', '10.1234/foo', status=PIDStatus.REGISTERED)
        pid = PersistentIdentifier.create(
            'recid', '7', status=PIDStatus.REGISTERED)
        pid.redirect(doi)

        # Record 8 - Unregistered PID
        PersistentIdentifier.create(
            'recid', '8', status=PIDStatus.RESERVED)

    db.session.commit()
Load test data fixture.