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_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)
Example #3
0
def push_to_orcid(sender, record, *args, **kwargs):
    """If needed, queue the push of the new changes to ORCID."""
    if not current_app.config['FEATURE_FLAG_ENABLE_ORCID_PUSH']:
        LOGGER.warning('ORCID push feature flag not enabled')
        return

    if not is_hep(record):
        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:
        orcid_tasks.orcid_push.apply_async(
            queue='orcid_push',
            kwargs={
                'orcid': orcid,
                'rec_id': record['control_number'],
                'oauth_token': access_token,
                'kwargs_to_pusher': kwargs_to_pusher,
            },
        )
 def test_push_new_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_push_new_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)
    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_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_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
    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_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