Exemplo n.º 1
0
def oaiset_update_records(minimal_record, db, es):
    """Fixture with records for query-based OAISet updating tests."""
    rec_ok = {
        'title': 'extra',
        '_oai': {
            'id': '12345',
            'sets': ['extra', 'user-foobar'],
            'updated': datetime(1970, 1, 1).isoformat(),
        }
    }
    # Record which needs removal of 'extra' from oai sets
    rec_remove = deepcopy(rec_ok)
    rec_remove['title'] = 'other'

    # Record which needs addition of 'extra' to oai sets
    rec_add = deepcopy(rec_ok)
    rec_add['_oai']['sets'] = [
        'user-foobar',
    ]
    records = [
        rec_ok,
        rec_remove,
        rec_add,
    ]

    rec_uuids = []
    for record_meta in records:
        rec = RecordMetadata()
        rec.json = deepcopy(record_meta)
        db.session.add(rec)
        db.session.commit()
        RecordIndexer().index_by_id(rec.id)
        rec_uuids.append(rec.id)
    current_search.flush_and_refresh('records')
    return rec_uuids
Exemplo n.º 2
0
def audit_records(minimal_record, db):
    """Audit test records."""
    records = {}
    for i in (1, 2, 3, 4):
        record = RecordMetadata()
        record.json = deepcopy(minimal_record)
        record.json['recid'] = i
        record.json['_oai'] = {
            'id': 'oai:{}'.format(i),
            'sets': [],
            'updated': datetime.utcnow().date().isoformat(),
        }

        db.session.add(record)
        db.session.commit()
        records[i] = ZenodoRecord(data=record.json, model=record)

        recid = PersistentIdentifier(pid_type='recid',
                                     pid_value=str(i),
                                     status='R',
                                     object_type='rec',
                                     object_uuid=record.id)
        db.session.add(recid)
        db.session.commit()
    return records
Exemplo n.º 3
0
def oaiset_update_records(minimal_record, db, es):
    """Fixture with records for query-based OAISet updating tests."""
    rec_ok = {
        'title': 'extra',
        '_oai': {
            'id': '12345',
            'sets': ['extra', 'user-foobar'],
            'updated': datetime(1970, 1, 1).isoformat(),
        }
    }
    # Record which needs removal of 'extra' from oai sets
    rec_remove = deepcopy(rec_ok)
    rec_remove['title'] = 'other'

    # Record which needs addition of 'extra' to oai sets
    rec_add = deepcopy(rec_ok)
    rec_add['_oai']['sets'] = ['user-foobar', ]
    records = [rec_ok, rec_remove, rec_add, ]

    rec_uuids = []
    for record_meta in records:
        rec = RecordMetadata()
        rec.json = deepcopy(record_meta)
        db.session.add(rec)
        db.session.commit()
        RecordIndexer().index_by_id(rec.id)
        rec_uuids.append(rec.id)
    current_search.flush_and_refresh('records')
    return rec_uuids
Exemplo n.º 4
0
def audit_records(minimal_record, db):
    """Audit test records."""
    records = {}
    for i in (1, 2, 3, 4):
        record = RecordMetadata()
        record.json = deepcopy(minimal_record)
        record.json['recid'] = i
        record.json['_oai'] = {
            'id': 'oai:{}'.format(i),
            'sets': [],
            'updated': datetime.utcnow().date().isoformat(),
        }

        db.session.add(record)
        db.session.commit()
        records[i] = str(ZenodoRecord(data=record.json, model=record).id)

        recid = PersistentIdentifier(pid_type='recid', pid_value=str(i),
                                     status='R', object_type='rec',
                                     object_uuid=record.id)
        oai_id = PersistentIdentifier(
            pid_type='oai', pid_value=record.json['_oai']['id'], status='R',
            object_type='rec', object_uuid=record.id)
        db.session.add(recid)
        db.session.add(oai_id)
        db.session.commit()
    return records
Exemplo n.º 5
0
def test_record_audit(record_audit, full_record, db, communities, users,
                      oaiid_pid):
    # Add the "ecfunded" community since it's usually being added automatically
    # after processing a deposit if the record has an EC grant.
    oaiid_pid.pid_value = full_record['communities'].append('ecfunded')

    # Mint the OAI identifier
    oaiid_pid.pid_value = full_record['_oai']['id']
    db.session.add(oaiid_pid)

    # Create the record metadata, to store the
    record_model = RecordMetadata()
    record_model.json = full_record
    db.session.add(record_model)

    db.session.commit()

    record = ZenodoRecord(data=full_record, model=record_model)
    check = RecordCheck(record_audit, record)
    check.perform()

    assert check.issues == {}
    assert check.is_ok is True
    assert check.dump() == {
        'record': {
            'recid': record['recid'],
            'object_uuid': str(record.id),
        },
        'issues': {},
    }
Exemplo n.º 6
0
def test_record_audit(record_audit, full_record, db, communities, users,
                      oaiid_pid):
    # Add the "ecfunded" community since it's usually being added automatically
    # after processing a deposit if the record has an EC grant.
    oaiid_pid.pid_value = full_record['communities'].append('ecfunded')

    # Mint the OAI identifier
    oaiid_pid.pid_value = full_record['_oai']['id']
    db.session.add(oaiid_pid)

    # Create the record metadata, to store the
    record_model = RecordMetadata()
    record_model.json = full_record
    db.session.add(record_model)

    db.session.commit()

    record = ZenodoRecord(data=full_record, model=record_model)
    check = RecordCheck(record_audit, record)
    check.perform()

    assert check.issues == {}
    assert check.is_ok is True
    assert check.dump() == {
        'record': {
            'recid': record['recid'],
            'object_uuid': str(record.id),
        },
        'issues': {},
    }