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

    indexer = RecordIndexer()
    index_queue = []

    # Record 1 - Live record
    with db.session.begin_nested():
        rec_uuid = uuid.uuid4()
        pid1 = PersistentIdentifier.create(
            'recid', '1', object_type='rec', object_uuid=rec_uuid,
            status=PIDStatus.REGISTERED)
        Record.create({
            'title': 'Registered',
            'description': 'This is an awesome description',
            # "mint" the record as recid minter does
            'control_number': '1',
        }, id_=rec_uuid)
        index_queue.append(pid1.object_uuid)

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

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

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

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

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

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

        for rec_idx in range(len(record_examples)):
            rec_uuid = uuid.uuid4()
            rec_pid = 8 + rec_idx
            pid1 = PersistentIdentifier.create(
                'recid', str(rec_pid), object_type='rec', object_uuid=rec_uuid,
                status=PIDStatus.REGISTERED)
            # "mint" the record as recid minter does
            record = dict(record_examples[rec_idx])
            record['control_number'] = str(rec_pid)
            # create the record
            Record.create(record, id_=rec_uuid)
            index_queue.append(rec_uuid)
    db.session.commit()

    for i in index_queue:
        indexer.index_by_id(i)
Load test data fixture.