async def test_400_should_call_recreate_df_and_retry(datafeed_loop, datafeed_api): datafeed_loop._retry_config = minimal_retry_config_with_attempts(2) datafeed_loop.recreate_datafeed = AsyncMock() datafeed_api.read_datafeed.side_effect = [ApiException(status=400), ApiException(status=500)] with pytest.raises(ApiException) as exception: await datafeed_loop.start() assert exception.value.status == 500 datafeed_loop.recreate_datafeed.assert_called_once() assert datafeed_api.read_datafeed.call_count == 2
async def test_should_retry(): strategies = [TestAuthenticationStrategy(), TestRefreshSessionStrategy(), TestReadDatafeedStrategy()] connection_key = Mock() connection_key.ssl = "ssl" exception_from_a_timeout = ClientConnectorError(connection_key, TimeoutError()) exception_from_a_timeout.__cause__ = TimeoutError() thing = FixedChainedExceptions([ApiException(429), ApiException(500), exception_from_a_timeout]) for s in strategies: s._retry_config = minimal_retry_config_with_attempts(4) value = await s._retryable_coroutine(thing) assert value is True assert thing.call_count == 4 thing.reset() # Reset the counters
def go(self): """Raise an ApiException until after count threshold has been crossed. Then return True. """ self.call_count += 1 if self.counter < self.count: self.counter += 1 raise ApiException(status=self.status, reason="Hi there, I'm an ApiException") return True
async def test_validate_jwt_get_pod_certificate_failure(): with patch("symphony.bdk.core.auth.ext_app_authenticator.validate_jwt") as mock_validate: mock_pod_api = AsyncMock() mock_pod_api.v1_podcert_get = AsyncMock(side_effect=ApiException(status=400)) with pytest.raises(ApiException): ext_app_authenticator = ExtensionAppAuthenticatorRsa(None, mock_pod_api, "app-id", None, minimal_retry_config()) await ext_app_authenticator.validate_jwt("my-jwt") mock_pod_api.v1_podcert_get.assert_called_once() mock_validate.assert_not_called()
async def test_get_all_presence_failed(presence_service, mocked_presence_api_client): mocked_presence_api_client.v2_users_presence_get.side_effect = ApiException(400) with pytest.raises(ApiException): await presence_service.get_all_presence(1234, 5000)
async def test_delete_presence_feed_failed(presence_service, mocked_presence_api_client): mocked_presence_api_client.v1_presence_feed_feed_id_delete_post.side_effect = ApiException(400) with pytest.raises(ApiException): await presence_service.delete_presence_feed("1234")
async def test_set_presence_failed(presence_service, mocked_presence_api_client): mocked_presence_api_client.v2_user_presence_post.side_effect = ApiException(400) with pytest.raises(ApiException): await presence_service.set_presence(PresenceStatus.AWAY, True)
async def test_external_presence_interest_failed(presence_service, mocked_presence_api_client): mocked_presence_api_client.v1_user_presence_register_post.side_effect = ApiException(400) uid_list = [1234] with pytest.raises(ApiException): await presence_service.external_presence_interest(uid_list)
async def read_df(**kwargs): if read_df.first_time: read_df.first_time = False raise ApiException(status=400, reason="") await asyncio.sleep(0.00001) # to force the switching of tasks return message_sent_event
async def raise_and_return_event(**kwargs): if raise_and_return_event.first: raise_and_return_event.first = False raise ApiException(400) await asyncio.sleep(0.00001) # to force the switching of tasks return message_sent_event