Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_retry_boto_call_returns_response_correctly(self):
def func(*args, **kwargs):
return sentinel.response
response = _retry_boto_call(func)()
assert response == sentinel.response
def test_retry_boto_call_raises_non_throttling_error(self):
mock_func = Mock()
mock_func.side_effect = ClientError(
{
"Error": {
"Code": 500,
"Message": "Boom!"
}
},
sentinel.operation
)
# The attribute function.__name__ is required by the decorator @wraps.
mock_func.__name__ = "mock_func"
with pytest.raises(ClientError) as e:
_retry_boto_call(mock_func)()
assert e.value.response["Error"]["Code"] == 500
assert e.value.response["Error"]["Message"] == "Boom!"
):
mock_func = Mock()
mock_func.side_effect = ClientError(
{
"Error": {
"Code": "Throttling",
"Message": "Request limit hit"
}
},
sentinel.operation
)
# The attribute function.__name__ is required by the decorator @wraps.
mock_func.__name__ = "mock_func"
with pytest.raises(RetryLimitExceededError):
_retry_boto_call(mock_func)()
mock_func.side_effect = [
ClientError(
{
"Error": {
"Code": "Throttling",
"Message": "Request limit hit"
}
},
sentinel.operation
),
sentinel.response
]
# The attribute function.__name__ is required by the decorator @wraps.
mock_func.__name__ = "mock_func"
_retry_boto_call(mock_func)()
mock_sleep.assert_called_once_with(1)