def test_whitelist_regex_any(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_called_once_with(self.orcid, self.recid, self.oauth_token)
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)
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()
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()
def test_push_new_work_already_existing(self): 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)
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()
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()
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()
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))
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.modules.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()
def test_orcid_push_feature_flag_orcid_push_whitelist_regex_none(api): orcid = '0000-0002-7638-5686' regex = '^$' with mock.patch('inspirehep.modules.orcid.tasks.push_record_with_orcid') as mock_push_record_with_orcid, \ mock.patch.dict( 'inspirehep.modules.orcid.tasks.current_app.config', { 'FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX': regex, }): orcid_push(orcid, 'rec_id', 'token') mock_push_record_with_orcid.assert_not_called()
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.modules.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()
def test_orcid_push_feature_flag_orcid_push_whitelist_regex_some(api): orcid = '0000-0002-7638-5686' regex = '^(0000-0002-7638-5686|0000-0002-7638-5687)$' with mock.patch('inspirehep.modules.orcid.tasks.attempt_push') as mock_attempt_push, \ mock.patch.dict( 'inspirehep.modules.orcid.tasks.current_app.config', { 'FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX': regex, }): orcid_push(orcid, 'rec_id', 'token') mock_attempt_push.assert_called_once_with(orcid, mock.ANY, mock.ANY)
def test_push_to_orcid_update_no_cache( vcr_cassette, redis_setup, ): rec_id = 4328 orcid = '0000-0002-2169-2152' token = 'fake-token' with override_config(**CONFIG): # Push update orcid_push(orcid, rec_id, token) # Check that the record was added: assert vcr_cassette.all_played
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.modules.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_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.modules.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_to_orcid_update_with_cache( vcr_cassette, redis_setup, ): rec_id = 4328 orcid = '0000-0002-2169-2152' token = 'fake-token' with override_config(**CONFIG): # Push as new orcid_push(orcid, rec_id, token) # Push the updated record orcid_push(orcid, rec_id, token) # Check that the update happened: assert vcr_cassette.all_played
def test_push_to_orcid_with_putcode_but_without_hash( vcr_cassette, redis_setup, ): rec_id = 4328 orcid = '0000-0002-2169-2152' token = 'fake-token' with override_config(**CONFIG): # Fetch the putcodes, no hashes present yet recache_author_putcodes(orcid, token) # Push the record orcid_push(orcid, rec_id, token) # Check that the update request didn't happen: assert vcr_cassette.all_played
def test_push_to_orcid_same_with_cache( mock_config, vcr_cassette, redis_setup, ): rec_id = 4328 orcid = '0000-0002-2169-2152' token = 'fake-token' # Push as new orcid_push(orcid, rec_id, token) # Push the same record again orcid_push(orcid, rec_id, token) # Check that the update request didn't happen: assert vcr_cassette.all_played
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)
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(exceptions.InputDataInvalidException): orcid_push('0000-0002-0000-XXXX', self.recid, self.oauth_token)
def test_push_new_work_already_existing(self): 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)
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(exceptions.InputDataInvalidException): orcid_push('0000-0002-0000-XXXX', self.recid, self.oauth_token)
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)
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))