Пример #1
0
def test_get_literature_recids_for_orcid_still_works_if_author_has_no_ids(
        inspire_app, datadir):
    data = json.loads((datadir / "1061000.json").read_text())
    create_record("aut", data=data)
    record = InspireRecord.get_record_by_pid_value(1061000, pid_type="aut")
    del record["ids"]
    record = InspireRecord.create_or_update(record)

    with pytest.raises(NoResultFound):
        get_literature_recids_for_orcid("0000-0003-4792-9178")
Пример #2
0
def test_get_literature_recids_for_orcid_still_works_if_author_has_no_orcid_id(
        inspire_app, datadir):
    data = json.loads((datadir / "1061000.json").read_text())
    create_record("aut", data=data)
    record = InspireRecord.get_record_by_pid_value(1061000, pid_type="aut")
    record["ids"] = [{
        "schema": "INSPIRE BAI",
        "value": "Maurizio.Martinelli.1"
    }]
    record = InspireRecord.create_or_update(record)

    with pytest.raises(NoResultFound):
        get_literature_recids_for_orcid("0000-0003-4792-9178")
Пример #3
0
def push_account_literature_to_orcid(orcid, token):
    recids = get_literature_recids_for_orcid(orcid)
    for recid in recids:
        orcid_push.apply_async(
            queue="orcid_push_legacy_tokens",
            kwargs={"orcid": orcid, "rec_id": recid, "oauth_token": token},
        )
Пример #4
0
def test_get_literature_recids_for_orcid(inspire_app, datadir):
    data_author = json.loads((datadir / "1061000.json").read_text())
    create_record("aut", data=data_author)
    data_literature = json.loads((datadir / "1496635.json").read_text())
    create_record("lit", data=data_literature)
    expected = [1496635]
    result = get_literature_recids_for_orcid("0000-0003-4792-9178")

    assert expected == result
Пример #5
0
def _import_legacy_orcid_tokens():
    if get_value(current_app.config,
                 "ORCID_APP_CREDENTIALS.consumer_key") is None:
        secho("consumer key for ORCID_APP_CREDENTIALS is None.", fg="yellow")
        return

    for user_data in legacy_orcid_arrays():
        secho(f"Processing {user_data}")
        try:
            orcid, token, email, name = user_data
            if push_access_tokens.is_access_token_invalid(token):
                secho(f"Token {token} is invalid. Skipping push.", fg="yellow")
                continue
            orcid_to_push = _register_user(name, email, orcid, token)
            if orcid_to_push:
                recids = get_literature_recids_for_orcid(orcid_to_push)
                if not recids:
                    secho("No records to push.")
                    continue
                for recid in recids:
                    secho(
                        f"Pushing orcid: {orcid_push}\trecid: {recid}\t token: {token}"
                    )
                    orcid_push.apply_async(
                        queue="orcid_push_legacy_tokens",
                        kwargs={
                            "orcid": orcid_to_push,
                            "rec_id": recid,
                            "oauth_token": token,
                        },
                    )
            else:
                secho("Cannot link user and token.", fg="yellow")
        except SQLAlchemyError as ex:
            secho(str(ex), fg="red")

    secho("No more data to process.")
    db.session.commit()
Пример #6
0
def test_get_literature_recids_for_orcid_raises_if_no_author_is_found(
        inspire_app):
    with pytest.raises(NoResultFound):
        get_literature_recids_for_orcid("THIS-ORCID-DOES-NOT-EXIST")