def test_legacy_orcid_arrays(base_app, db, es, redis_setup): """Test the generator functionality.""" push_to_redis(SAMPLE_USER_2) push_to_redis(SAMPLE_USER) # Check initial state of queue assert redis_setup.llen("legacy_orcid_tokens") == 2 # Take all the records from the queue json_list = list(legacy_orcid_arrays()) # Check if results are expected, and that redis is empty assert json_list == [record_dict_to_array(x) for x in [SAMPLE_USER, SAMPLE_USER_2]] assert redis_setup.llen("legacy_orcid_tokens") == 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()