def test_get_literature_recids_for_orcid_still_works_if_author_has_no_orcid_id(isolated_app): record = get_db_record('aut', 1061000) record['ids'] = [{'schema': 'INSPIRE BAI', 'value': 'Maurizio.Martinelli.1'}] record = InspireRecord.create_or_update(record) record.commit() with pytest.raises(NoResultFound): get_literature_recids_for_orcid('0000-0003-4792-9178')
def test_get_literature_recids_for_orcid_still_works_if_author_has_no_ids(isolated_app): record = get_db_record('aut', 1061000) del record['ids'] record = InspireRecord.create_or_update(record) record.commit() with pytest.raises(NoResultFound): get_literature_recids_for_orcid('0000-0003-4792-9178')
def test_get_literature_recids_for_orcid_raises_if_two_authors_are_found(isolated_app): record = get_db_record('aut', 1061000) record['control_number'] = 1061001 record = InspireRecord.create_or_update(record) record.commit() with pytest.raises(MultipleResultsFound): get_literature_recids_for_orcid('0000-0003-4792-9178')
def test_get_literature_recids_for_orcid_still_works_if_author_has_no_ids( isolated_app): record = get_db_record('aut', 1061000) del record['ids'] record = InspireRecord.create_or_update(record) record.commit() with pytest.raises(NoResultFound): get_literature_recids_for_orcid('0000-0003-4792-9178')
def test_get_literature_recids_for_orcid_raises_if_two_authors_are_found( isolated_app): record = get_db_record('aut', 1061000) record['control_number'] = 1061001 record = InspireRecord.create_or_update(record) record.commit() with pytest.raises(MultipleResultsFound): get_literature_recids_for_orcid('0000-0003-4792-9178')
def test_get_literature_recids_for_orcid_still_works_if_author_has_no_orcid_id( isolated_app): record = get_db_record('aut', 1061000) record['ids'] = [{ 'schema': 'INSPIRE BAI', 'value': 'Maurizio.Martinelli.1' }] record = InspireRecord.create_or_update(record) record.commit() with pytest.raises(NoResultFound): get_literature_recids_for_orcid('0000-0003-4792-9178')
def import_legacy_orcid_tokens(): """Task to import OAUTH ORCID tokens from legacy.""" if get_value(current_app.config, 'ORCID_APP_CREDENTIALS.consumer_key') is None: return for user_data in legacy_orcid_arrays(): try: orcid, token, email, name = user_data orcid_to_push = _register_user(name, email, orcid, token) if orcid_to_push: LOGGER.info( 'allow_push now enabled on %s, will push all works now', orcid_to_push) recids = get_literature_recids_for_orcid(orcid_to_push) for recid in recids: orcid_push.apply_async( queue='orcid_push_legacy_tokens', kwargs={ 'orcid': orcid_to_push, 'rec_id': recid, 'oauth_token': token, }, ) except SQLAlchemyError as ex: LOGGER.exception(ex) db.session.commit()
def import_legacy_orcid_tokens(self): """ Celery task to import OAUTH ORCID tokens from legacy. Note: bind=True for compatibility with @time_execution. """ if get_value(current_app.config, 'ORCID_APP_CREDENTIALS.consumer_key') is None: return for user_data in legacy_orcid_arrays(): try: orcid, token, email, name = user_data if push_access_tokens.is_access_token_invalid(token): continue orcid_to_push = _register_user(name, email, orcid, token) if orcid_to_push: LOGGER.info( 'allow_push now enabled on %s, will push all works now', orcid_to_push ) recids = get_literature_recids_for_orcid(orcid_to_push) for recid in recids: orcid_push.apply_async( queue='orcid_push_legacy_tokens', kwargs={ 'orcid': orcid_to_push, 'rec_id': recid, 'oauth_token': token, }, ) except SQLAlchemyError as ex: LOGGER.exception(ex) db.session.commit()
def test_get_literature_recids_for_orcid_raises_if_no_author_is_found( isolated_app): with pytest.raises(NoResultFound): get_literature_recids_for_orcid('THIS-ORCID-DOES-NOT-EXIST')
def test_get_literature_recids_for_orcid(isolated_app): expected = [1496635] result = get_literature_recids_for_orcid('0000-0003-4792-9178') assert expected == result
def test_get_literature_recids_for_orcid_raises_if_no_author_is_found(isolated_app): with pytest.raises(NoResultFound): get_literature_recids_for_orcid('THIS-ORCID-DOES-NOT-EXIST')
def test_get_literature_recids_for_orcid(isolated_app): expected = [1496635] result = get_literature_recids_for_orcid('0000-0003-4792-9178') assert expected == result