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_single_token(self):
        orcid = "0000-0003-4792-9178"
        expected_remote_token = TestRemoteToken.create_for_orcid(orcid).remote_token

        orcids_and_tokens = push_access_tokens.get_access_tokens([orcid])

        assert len(orcids_and_tokens) == 1
        assert orcids_and_tokens[0].id == orcid
        assert orcids_and_tokens[0].access_token == expected_remote_token.access_token
    def test_allow_push(self):
        orcid1 = "0000-0003-4792-9178"
        expected_remote_token = TestRemoteToken.create_for_orcid(orcid1).remote_token
        orcid2 = "0000-0003-4792-9179"
        TestRemoteToken.create_for_orcid(orcid2, allow_push=False).remote_token

        orcids_and_tokens = push_access_tokens.get_access_tokens([orcid1, orcid2])

        assert len(orcids_and_tokens) == 1
        assert orcids_and_tokens[0].id == orcid1
        assert orcids_and_tokens[0].access_token == expected_remote_token.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)
    def test_multiple_tokens(self):
        orcid1 = "0000-0003-4792-9178"
        expected_remote_token1 = TestRemoteToken.create_for_orcid(orcid1).remote_token
        orcid2 = "0000-0003-4792-9179"
        expected_remote_token2 = TestRemoteToken.create_for_orcid(orcid2).remote_token

        orcids_and_tokens = push_access_tokens.get_access_tokens([orcid1, orcid2])

        assert len(orcids_and_tokens) == 2
        assert orcids_and_tokens[0].id == orcid1
        assert orcids_and_tokens[0].access_token == expected_remote_token1.access_token
        assert orcids_and_tokens[1].id == orcid2
        assert orcids_and_tokens[1].access_token == expected_remote_token2.access_token
Exemplo n.º 7
0
def test_push_access_token_is_removed_when_orcid_is_moved(
        inspire_app, override_config, user_remote_account):
    orcid = user_remote_account.remote_account.extra_data["orcid"]
    data = {
        "ids": [
            {
                "schema": "INSPIRE BAI",
                "value": "J.Smith.1"
            },
            {
                "schema": "ORCID",
                "value": orcid
            },
        ]
    }
    create_record("aut", data=data)
    new_orcid = "0000-0002-1825-0097"
    with override_config(MAIL_SUPPRESS_SEND=False):
        update_moved_orcid(orcid, new_orcid)
    assert not get_access_tokens([orcid])
    assert user_remote_account.remote_account.extra_data["orcid"] == new_orcid
    assert not user_remote_account.remote_account.extra_data["allow_push"]
Exemplo n.º 8
0
def push_to_orcid(record):
    """If needed, queue the push of the new changes to ORCID."""
    if not current_app.config["FEATURE_FLAG_ENABLE_ORCID_PUSH"]:
        LOGGER.info("ORCID push feature flag not enabled")
        return

    # Ensure there is a control number. This is not always the case because of broken store_record.
    if "control_number" not in record:
        return

    orcids = get_orcids_for_push(record)
    orcids_and_tokens = push_access_tokens.get_access_tokens(orcids)

    kwargs_to_pusher = dict(record_db_version=record.model.version_id)

    for orcid, access_token in orcids_and_tokens:
        _send_push_task(
            kwargs={
                "orcid": orcid,
                "rec_id": record["control_number"],
                "oauth_token": access_token,
                "kwargs_to_pusher": kwargs_to_pusher,
            })