def test_happy_flow(self):
        push_access_tokens.delete_access_token(self.remote_token.access_token,
                                               self.orcid)

        assert not push_access_tokens.get_access_tokens([self.orcid])
        assert push_access_tokens.is_access_token_invalid(
            self.remote_token.access_token)
 def test_push_updated_work_invalid_data_token(self):
     access_token = "tokeninvalid"
     TestRemoteToken.create_for_orcid(self.orcid, access_token=access_token)
     pusher = domain_models.OrcidPusher(self.orcid, self.recid,
                                        access_token)
     with pytest.raises(exceptions.TokenInvalidDeletedException):
         pusher.push()
     assert not push_access_tokens.get_access_tokens([self.orcid])
     assert push_access_tokens.is_access_token_invalid(access_token)
 def test_delete_work_invalid_token(self):
     access_token = "tokeninvalid"
     TestRemoteToken.create_for_orcid(self.orcid, access_token=access_token)
     pusher = domain_models.OrcidPusher(self.orcid, self.recid,
                                        access_token)
     # ORCID_APP_CREDENTIALS is required because ORCID adds it as source_client_id_path.
     with override_config(
             ORCID_APP_CREDENTIALS={"consumer_key": "0000-0001-8607-8906"}
     ), pytest.raises(exceptions.TokenInvalidDeletedException):
         pusher.push()
     assert not push_access_tokens.get_access_tokens([self.orcid])
     assert push_access_tokens.is_access_token_invalid(access_token)
Exemplo n.º 4
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()
 def test_valid(self):
     assert not push_access_tokens.is_access_token_invalid("nonexisting")
 def test_invalid(self):
     self.cache.write_invalid_token(self.orcid)
     assert push_access_tokens.is_access_token_invalid(self.token_plain)