def test_missing_files(record_audit, minimal_record, record_files, issue): minimal_record.update({'_files': record_files}) check = RecordCheck(record_audit, minimal_record) check._missing_files() result_issue = check.issues.get('files', {}).get('missing') assert bool(result_issue) == bool(issue)
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': {}, }
def test_duplicate_files(record_audit, minimal_record, record_files, issue): minimal_record.update({'_files': record_files}) check = RecordCheck(record_audit, minimal_record) check._duplicate_files() result_issue = check.issues.get('files', {}).get('duplicates') assert bool(result_issue) == bool(issue) if result_issue and issue: assert result_issue == issue
def test_oai_required(record_audit, minimal_record, record_oai, issue): minimal_record.update({'_oai': record_oai}) check = RecordCheck(record_audit, minimal_record) check._oai_required() result_issue = check.issues.get('oai', {}).get('missing') assert bool(result_issue) == bool(issue) if result_issue and issue: assert result_issue == issue
def test_duplicate_grants(record_audit, minimal_record, record_grants, issue): minimal_record.update({'grants': record_grants}) check = RecordCheck(record_audit, minimal_record) check._duplicate_grants() result_issue = check.issues.get('grants', {}).get('duplicates') assert bool(result_issue) == bool(issue) if result_issue and issue: assert len(result_issue) == len(issue) assert set(result_issue) == set(issue)
def test_oai_duplicate_sets(record_audit, minimal_record, record_oai, issue): minimal_record.update({'_oai': record_oai}) check = RecordCheck(record_audit, minimal_record) check._oai_duplicate_sets() result_issue = check.issues.get('oai', {}).get('duplicate_oai_sets') assert bool(result_issue) == bool(issue) if result_issue and issue: assert len(result_issue) == len(issue) assert set(result_issue) == set(issue)
def test_multiple_buckets(record_audit, minimal_record, record_files, issue): minimal_record.update({'_files': record_files}) check = RecordCheck(record_audit, minimal_record) check._multiple_buckets() result_issue = check.issues.get('files', {}).get('multiple_buckets') assert bool(result_issue) == bool(issue) if result_issue and issue: assert len(result_issue) == len(issue) assert set(result_issue) == set(issue)
def test_oai_community_correspondence(record_audit, minimal_record, db, record_communities, record_oai, issue): minimal_record.update({'communities': record_communities}) minimal_record.update({'_oai': {'sets': record_oai}}) check = RecordCheck(record_audit, minimal_record) check._oai_community_correspondence() result_issue = check.issues.get('oai', {}) assert bool(result_issue) == bool(issue) if result_issue and issue: assert result_issue == issue
def test_unresolvable_owners(record_audit, minimal_record, users, record_owners, issue): minimal_record.update({'owners': record_owners}) check = RecordCheck(record_audit, minimal_record) check._unresolvable_owners() result_issue = check.issues.get('owners', {}).get('unresolvable') assert bool(result_issue) == bool(issue) if result_issue and issue: assert len(result_issue) == len(issue) assert set(result_issue) == set(issue)
def test_bucket_mismatch(record_audit, minimal_record, record_bucket, record_files, issue): minimal_record.update({'_buckets': {'record': record_bucket}}) minimal_record.update({'_files': record_files}) check = RecordCheck(record_audit, minimal_record) check._bucket_mismatch() result_issue = check.issues.get('files', {}).get('bucket_mismatch') assert bool(result_issue) == bool(issue) if result_issue and issue: assert len(result_issue) == len(issue) assert result_issue == issue
def test_oai_non_minted_pid(record_audit, minimal_record, db, oaiid_pid, record_oai, issue): db.session.add(oaiid_pid) db.session.commit() minimal_record.update({'_oai': record_oai}) check = RecordCheck(record_audit, minimal_record) check._oai_non_minted_pid() result_issue = check.issues.get('oai', {}).get('non_minted_pid') assert bool(result_issue) == bool(issue) if result_issue and issue: assert result_issue == issue
def test_jsonschema(app, record_audit, minimal_record): check = RecordCheck(record_audit, ZenodoRecord(minimal_record)) check.jsonschema() assert check.issues.get('jsonschema') is None minimal_record['invalid_key'] = 'should not be here' check = RecordCheck(record_audit, ZenodoRecord(minimal_record)) check.jsonschema() assert check.issues.get('jsonschema')