Example #1
0
def test_datacite_register_fail(mocker, app, db, es, minimal_record):
    # Make the datacite API unavailable
    dc_mock = mocker.patch(
        'invenio_pidstore.providers.datacite.DataCiteMDSClient')
    dc_mock().metadata_post.side_effect = datacite.errors.HttpError()

    # Create a reserved recid
    record = Record.create(minimal_record)
    record_uuid = record.id
    recid = record['recid']
    recid_pid = PersistentIdentifier.create('recid',
                                            recid,
                                            status=PIDStatus.RESERVED)

    # Mint the record
    zenodo_record_minter(record_uuid, record)
    record.commit()
    db.session.commit()

    with pytest.raises(datacite.errors.HttpError):
        datacite_register.apply((recid_pid.pid_value, str(record_uuid)))

    # Check that the task was retried ("max_retries" + 1) times
    dc_calls = len(dc_mock().metadata_post.mock_calls)
    assert dc_calls == datacite_register.max_retries + 1
Example #2
0
    def create_deposit_and_record(pid_value, owner):
        """Utility function for creating records and deposits."""
        recid = PersistentIdentifier.create(
            'recid', pid_value, status=PIDStatus.RESERVED)
        pv = PIDVersioning(parent=conceptrecid)
        pv.insert_draft_child(recid)

        depid = PersistentIdentifier.create(
            'depid', pid_value, status=PIDStatus.REGISTERED)
        deposit = ZenodoRecord.create({'_deposit': {'id': depid.pid_value},
                                       'conceptrecid': conceptrecid.pid_value,
                                       'recid': recid.pid_value})
        deposit.commit()
        depid.assign('rec', deposit.id)

        record_metadata = deepcopy(minimal_record)
        record_metadata['_deposit'] = {'id': depid.pid_value}
        record_metadata['conceptrecid'] = conceptrecid.pid_value
        record_metadata['recid'] = int(recid.pid_value)
        record_metadata['owners'] = [owner.id]
        record = ZenodoRecord.create(record_metadata)
        zenodo_record_minter(record.id, record)
        record.commit()

        return (depid, deposit, recid, record)
Example #3
0
def test_doi_minting(db, doi_in, doi_out):
    """Test using same integer for dep/rec ids."""
    dep_uuid, rec_uuid = uuid4(), uuid4()
    data = dict(doi=doi_in)
    zenodo_deposit_minter(dep_uuid, data)
    zenodo_record_minter(rec_uuid, data)
    db.session.commit()

    pid = PersistentIdentifier.get('doi', doi_out)
    assert pid.object_uuid == rec_uuid
    assert pid.status == PIDStatus.RESERVED
Example #4
0
    def create_versioned_record(recid_value, conceptrecid):
        """Utility function for creating versioned records."""
        recid = PersistentIdentifier.create(
            'recid', recid_value, status=PIDStatus.RESERVED)
        pv = PIDVersioning(parent=conceptrecid)
        pv.insert_draft_child(recid)

        record_metadata = deepcopy(minimal_record)
        record_metadata['conceptrecid'] = conceptrecid.pid_value
        record_metadata['recid'] = int(recid.pid_value)
        record = ZenodoRecord.create(record_metadata)
        zenodo_record_minter(record.id, record)
        record.commit()

        return recid, record
def test_datacite_register(dc_mock, app, db, es, minimal_record):
    # Create a reserved recid
    record = Record.create(minimal_record)
    record_uuid = record.id
    recid = record['recid']
    recid_pid = PersistentIdentifier.create(
        'recid', recid, status=PIDStatus.RESERVED)

    # Mint the record
    zenodo_record_minter(record_uuid, record)
    record.commit()
    db.session.commit()

    datacite_register(recid_pid.pid_value, str(record_uuid))
    dc_mock().doi_post.assert_called_once_with(
        record['doi'], 'https://zenodo.org/record/{}'.format(recid))
Example #6
0
def test_double_minting_depid_recid(db):
    """Test using same integer for dep/rec ids."""
    dep_uuid = uuid4()
    data = dict()
    pid = zenodo_deposit_minter(dep_uuid, data)
    # Assert values added to data. Depid and recid have IDs starting from
    # '2' since the conceptrecid is minted first
    assert data['_deposit']['id'] == '2'
    assert data['conceptrecid'] == '1'
    assert data['recid'] == 2
    assert 'doi' not in data
    # Assert pid values
    assert pid.pid_type == 'depid'
    assert pid.pid_value == '2'
    assert pid.status == PIDStatus.REGISTERED
    assert pid.object_uuid == dep_uuid
    # Assert reservation of recid.
    assert PersistentIdentifier.get('recid', pid.pid_value).status \
        == PIDStatus.RESERVED
    db.session.commit()

    # Assert registration of recid.
    rec_uuid = uuid4()
    pid = zenodo_record_minter(rec_uuid, data)
    assert pid.pid_type == 'recid'
    assert pid.pid_value == '2'
    assert pid.status == PIDStatus.REGISTERED
    assert pid.object_uuid == rec_uuid
    assert data['doi'] == '10.5072/zenodo.2'
    assert data['_oai']['id'] == 'oai:zenodo.org:2'
Example #7
0
def test_datacite_register_fail(dc_mock, app, db, es, minimal_record):
    # Make the datacite API unavailable
    dc_mock().metadata_post.side_effect = datacite.errors.HttpError()

    # Create a reserved recid
    record = Record.create(minimal_record)
    record_uuid = record.id
    recid = record['recid']
    recid_pid = PersistentIdentifier.create(
        'recid', recid, status=PIDStatus.RESERVED)

    # Mint the record
    zenodo_record_minter(record_uuid, record)
    record.commit()
    db.session.commit()

    with pytest.raises(datacite.errors.HttpError):
        datacite_register.apply((recid_pid.pid_value, str(record_uuid)))

    # Check that the task was retried ("max_retries" + 1) times
    dc_calls = len(dc_mock().metadata_post.mock_calls)
    assert dc_calls == datacite_register.max_retries + 1