mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
@@ -575,3 +575,22 @@ def test_send_canary_to_cbc_proxy_invokes_cbc_proxy_client(
|
||||
uuid.UUID(identifier)
|
||||
except BaseException:
|
||||
pytest.fail(f"{identifier} is not a valid uuid")
|
||||
|
||||
|
||||
def test_trigger_link_tests_invokes_cbc_proxy_client(
|
||||
mocker,
|
||||
):
|
||||
mock_send_link_test = mocker.patch(
|
||||
'app.cbc_proxy_client.send_link_test',
|
||||
)
|
||||
|
||||
scheduled_tasks.trigger_link_tests()
|
||||
|
||||
mock_send_link_test.assert_called
|
||||
# the 0th argument of the call to send_link_test
|
||||
identifier = mock_send_link_test.mock_calls[0][1][0]
|
||||
|
||||
try:
|
||||
uuid.UUID(identifier)
|
||||
except BaseException:
|
||||
pytest.fail(f"{identifier} is not a valid uuid")
|
||||
|
||||
@@ -74,6 +74,7 @@ def test_cbc_proxy_create_and_send_invokes_function(mocker, cbc_proxy):
|
||||
payload = json.loads(payload_bytes)
|
||||
|
||||
assert payload['identifier'] == identifier
|
||||
assert payload['message_type'] == 'alert'
|
||||
assert payload['headline'] == headline
|
||||
assert payload['description'] == description
|
||||
assert payload['areas'] == areas
|
||||
@@ -251,3 +252,89 @@ def test_cbc_proxy_send_canary_handles_function_error(mocker, cbc_proxy):
|
||||
InvocationType='RequestResponse',
|
||||
Payload=mocker.ANY,
|
||||
)
|
||||
|
||||
|
||||
def test_cbc_proxy_send_link_test_invokes_function(mocker, cbc_proxy):
|
||||
identifier = str(uuid.uuid4())
|
||||
|
||||
ld_client_mock = mocker.patch.object(
|
||||
cbc_proxy,
|
||||
'_lambda_client',
|
||||
create=True,
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.return_value = {
|
||||
'StatusCode': 200,
|
||||
}
|
||||
|
||||
cbc_proxy.send_link_test(
|
||||
identifier=identifier,
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.assert_called_once_with(
|
||||
FunctionName='bt-ee-1-proxy',
|
||||
InvocationType='RequestResponse',
|
||||
Payload=mocker.ANY,
|
||||
)
|
||||
|
||||
kwargs = ld_client_mock.invoke.mock_calls[0][-1]
|
||||
payload_bytes = kwargs['Payload']
|
||||
payload = json.loads(payload_bytes)
|
||||
|
||||
assert payload['identifier'] == identifier
|
||||
assert payload['message_type'] == 'test'
|
||||
|
||||
|
||||
def test_cbc_proxy_send_link_test_handles_invoke_error(mocker, cbc_proxy):
|
||||
identifier = str(uuid.uuid4())
|
||||
|
||||
ld_client_mock = mocker.patch.object(
|
||||
cbc_proxy,
|
||||
'_lambda_client',
|
||||
create=True,
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.return_value = {
|
||||
'StatusCode': 400,
|
||||
}
|
||||
|
||||
with pytest.raises(Exception) as e:
|
||||
cbc_proxy.send_link_test(
|
||||
identifier=identifier,
|
||||
)
|
||||
|
||||
assert e.match('Function exited with unhandled exception')
|
||||
|
||||
ld_client_mock.invoke.assert_called_once_with(
|
||||
FunctionName='bt-ee-1-proxy',
|
||||
InvocationType='RequestResponse',
|
||||
Payload=mocker.ANY,
|
||||
)
|
||||
|
||||
|
||||
def test_cbc_proxy_send_link_test_handles_function_error(mocker, cbc_proxy):
|
||||
identifier = str(uuid.uuid4())
|
||||
|
||||
ld_client_mock = mocker.patch.object(
|
||||
cbc_proxy,
|
||||
'_lambda_client',
|
||||
create=True,
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.return_value = {
|
||||
'StatusCode': 200,
|
||||
'FunctionError': 'something',
|
||||
}
|
||||
|
||||
with pytest.raises(Exception) as e:
|
||||
cbc_proxy.send_link_test(
|
||||
identifier=identifier,
|
||||
)
|
||||
|
||||
assert e.match('Could not invoke lambda')
|
||||
|
||||
ld_client_mock.invoke.assert_called_once_with(
|
||||
FunctionName='bt-ee-1-proxy',
|
||||
InvocationType='RequestResponse',
|
||||
Payload=mocker.ANY,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user