mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
catch boto exceptions
these will happen if, for example, you have issues connecting to AWS or permission issues. Still failover if we get one of these exceptions, as I think it might be possible to have a problem only related to one of the lambdas.
This commit is contained in:
@@ -4,6 +4,7 @@ from collections import namedtuple
|
||||
from datetime import datetime
|
||||
from unittest.mock import Mock, call
|
||||
|
||||
from botocore.exceptions import ClientError as BotoClientError
|
||||
import pytest
|
||||
|
||||
from app.clients.cbc_proxy import (
|
||||
@@ -316,6 +317,50 @@ def test_cbc_proxy_vodafone_cancel_invokes_function(mocker, cbc_proxy_vodafone):
|
||||
assert payload['sent'] == sent
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cbc', ['ee', 'vodafone', 'three', 'o2'])
|
||||
def test_cbc_proxy_will_failover_to_second_lambda_if_boto_client_error(
|
||||
mocker,
|
||||
cbc_proxy_client,
|
||||
cbc
|
||||
):
|
||||
cbc_proxy = cbc_proxy_client.get_proxy(cbc)
|
||||
|
||||
ld_client_mock = mocker.patch.object(
|
||||
cbc_proxy,
|
||||
'_lambda_client',
|
||||
create=True,
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.side_effect = BotoClientError({}, 'error')
|
||||
|
||||
with pytest.raises(CBCProxyRetryableException) as e:
|
||||
cbc_proxy.create_and_send_broadcast(
|
||||
identifier='my-identifier',
|
||||
message_number='0000007b',
|
||||
headline='my-headline',
|
||||
description='test-description',
|
||||
areas=EXAMPLE_AREAS,
|
||||
sent='a-passed-through-sent-value',
|
||||
expires='a-passed-through-expires-value',
|
||||
channel="severe",
|
||||
)
|
||||
|
||||
assert e.match(f'Lambda failed for both {cbc}-1-proxy and {cbc}-2-proxy')
|
||||
|
||||
assert ld_client_mock.invoke.call_args_list == [
|
||||
call(
|
||||
FunctionName=f'{cbc}-1-proxy',
|
||||
InvocationType='RequestResponse',
|
||||
Payload=mocker.ANY,
|
||||
),
|
||||
call(
|
||||
FunctionName=f'{cbc}-2-proxy',
|
||||
InvocationType='RequestResponse',
|
||||
Payload=mocker.ANY,
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cbc', ['ee', 'vodafone', 'three', 'o2'])
|
||||
def test_cbc_proxy_will_failover_to_second_lambda_if_function_error(
|
||||
mocker,
|
||||
|
||||
Reference in New Issue
Block a user