Example #1
0
 def test_push_new_work_happy_flow(self):
     with override_config(
             FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
             FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
     ):
         orcid_push(self.orcid, self.recid, self.oauth_token)
     assert not self.cache.has_work_content_changed(self.inspire_record)
Example #2
0
    def _push_work_with_clashing_identifier(self):
        putcode_getter = OrcidPutcodeGetter(self.orcid, self.oauth_token)

        ids = self.converter.added_external_identifiers
        putcodes_recids = putcode_getter.get_putcodes_and_recids_by_identifiers_iter(
            ids)
        updated_putcodes_recid = self._delete_works_with_duplicated_putcodes(
            putcodes_recids)

        for (recid, putcode) in updated_putcodes_recid.items():

            if not putcode or not recid:
                continue
            if recid == self.recid:
                continue
            # Local import to avoid import error.
            from inspirehep.orcid import tasks

            tasks.orcid_push(
                self.orcid,
                recid,
                self.oauth_token,
                dict(
                    pushing_duplicated_identifier=True,
                    record_db_version=self.record_db_version,
                ),
            )
Example #3
0
    def test_main_feature_flag(self):
        regex = ".*"
        with override_config(
                FEATURE_FLAG_ENABLE_ORCID_PUSH=False,
                FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=regex,
        ):
            orcid_push(self.orcid, self.recid, self.oauth_token)

        self.mock_pusher.assert_not_called()
Example #4
0
 def test_push_new_work_already_existing(self):
     self.cache.delete_work_putcode()
     with override_config(
             FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
             FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
             ORCID_APP_CREDENTIALS={"consumer_key": "0000-0001-8607-8906"},
     ):
         orcid_push(self.orcid, self.recid, self.oauth_token)
     assert not self.cache.has_work_content_changed(self.inspire_record)
Example #5
0
    def test_whitelist_regex_none(self):
        regex = "^$"
        with override_config(
                FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
                FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=regex,
        ):
            orcid_push(self.orcid, self.recid, self.oauth_token)

        self.mock_pusher.assert_not_called()
Example #6
0
    def test_happy_flow(self):
        with override_config(
                FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
                FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
        ):
            orcid_push(self.orcid, self.recid, self.oauth_token)

        self.mock_pusher.assert_called_once_with(self.orcid, self.recid,
                                                 self.oauth_token)
        self.mock_pusher.return_value.push.assert_called_once()
Example #7
0
    def test_whitelist_regex_some(self):
        regex = "^(0000-0002-7638-5686|0000-0002-7638-5687)$"
        with override_config(
                FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
                FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=regex,
        ):
            orcid_push(self.orcid, self.recid, self.oauth_token)

            self.mock_pusher.assert_called_once_with(self.orcid, self.recid,
                                                     self.oauth_token)
Example #8
0
 def test_stale_record_db_version(self):
     with override_config(
             FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
             FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
     ), pytest.raises(domain_exceptions.StaleRecordDBVersionException):
         orcid_push(
             self.orcid,
             self.recid,
             self.oauth_token,
             kwargs_to_pusher=dict(record_db_version=100),
         )
Example #9
0
    def test_retry_not_triggered(self):
        self.mock_pusher.return_value.push.side_effect = IOError

        with override_config(
                FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
                FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
        ), mock.patch("inspirehep.orcid.tasks.orcid_push.retry"
                      ) as mock_orcid_push_task_retry, pytest.raises(IOError):
            orcid_push(self.orcid, self.recid, self.oauth_token)

        self.mock_pusher.assert_called_once_with(self.orcid, self.recid,
                                                 self.oauth_token)
        self.mock_pusher.return_value.push.assert_called_once()
        mock_orcid_push_task_retry.assert_not_called()
Example #10
0
    def test_retry_triggered(self):
        exc = RequestException()
        exc.response = mock.Mock()
        exc.request = mock.Mock()
        self.mock_pusher.return_value.push.side_effect = exc

        with override_config(
                FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
                FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
        ), mock.patch(
                "inspirehep.orcid.tasks.orcid_push.retry",
                side_effect=RequestException
        ) as mock_orcid_push_task_retry, pytest.raises(RequestException):
            orcid_push(self.orcid, self.recid, self.oauth_token)

        self.mock_pusher.assert_called_once_with(self.orcid, self.recid,
                                                 self.oauth_token)
        self.mock_pusher.return_value.push.assert_called_once()
        mock_orcid_push_task_retry.assert_called_once()
    def test_push_new_work_moved_permanently_orcid_account_exception(
            self, override_config):
        exc = MovedPermanentlyException()
        exc.args = (
            "{'response-code': 301, 'developer-message': '301 Moved Permanently: This account is deprecated. Please refer to account: https://qa.orcid.org/0000-0003-1134-6827. ORCID https://qa.orcid.org/0000-1111-0000-0000', 'user-message': 'The resource was not found.'",
        )
        self._patcher = mock.patch(
            "inspirehep.orcid.domain_models.OrcidPusher._post_or_put_work")
        self.mock_pusher = self._patcher.start()
        self.mock_pusher.side_effect = exc
        with override_config(
                FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
                FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
        ), mock.patch("inspirehep.orcid.domain_models.utils.update_moved_orcid"
                      ) as mock_update_orcid, pytest.raises(
                          MovedPermanentlyException):
            orcid_push(self.orcid, self.recid, self.oauth_token)

        assert mock_update_orcid.mock_calls[0][1] == (
            "0000-0003-1134-6827",
            "0000-1111-0000-0000",
        )
        self._patcher.stop()
Example #12
0
 def test_push_new_work_invalid_data_orcid(self):
     with override_config(
             FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
             FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
     ), pytest.raises(domain_exceptions.InputDataInvalidException):
         orcid_push("0000-0003-0000-XXXX", self.recid, self.oauth_token)