mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
Separate functions for cbc clients
Also move message_format to the clients.
This commit is contained in:
@@ -24,6 +24,11 @@ def cbc_proxy_ee(cbc_proxy_client):
|
||||
return cbc_proxy_client.get_proxy('ee')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cbc_proxy_vodafone(cbc_proxy_client):
|
||||
return cbc_proxy_client.get_proxy('vodafone')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('provider_name, expected_provider_class', [
|
||||
('ee', CBCProxyEE),
|
||||
('canary', CBCProxyCanary),
|
||||
@@ -51,7 +56,7 @@ def test_cbc_proxy_lambda_client_has_correct_keys(cbc_proxy_ee):
|
||||
assert secret == 'cbc-proxy-aws-secret-access-key'
|
||||
|
||||
|
||||
def test_cbc_proxy_create_and_send_invokes_function(mocker, cbc_proxy_ee):
|
||||
def test_cbc_proxy_ee_create_and_send_invokes_function(mocker, cbc_proxy_ee):
|
||||
identifier = 'my-identifier'
|
||||
headline = 'my-headline'
|
||||
description = 'my-description'
|
||||
@@ -84,7 +89,6 @@ def test_cbc_proxy_create_and_send_invokes_function(mocker, cbc_proxy_ee):
|
||||
cbc_proxy_ee.create_and_send_broadcast(
|
||||
identifier=identifier,
|
||||
message_number='0000007b',
|
||||
message_format='cbc',
|
||||
headline=headline,
|
||||
description=description,
|
||||
areas=areas,
|
||||
@@ -102,7 +106,7 @@ def test_cbc_proxy_create_and_send_invokes_function(mocker, cbc_proxy_ee):
|
||||
payload = json.loads(payload_bytes)
|
||||
|
||||
assert payload['identifier'] == identifier
|
||||
assert payload['message_number'] == '0000007b'
|
||||
assert 'message_number' not in payload
|
||||
assert payload['message_format'] == 'cbc'
|
||||
assert payload['message_type'] == 'alert'
|
||||
assert payload['headline'] == headline
|
||||
@@ -112,6 +116,66 @@ def test_cbc_proxy_create_and_send_invokes_function(mocker, cbc_proxy_ee):
|
||||
assert payload['expires'] == expires
|
||||
|
||||
|
||||
def test_cbc_proxy_vodafone_create_and_send_invokes_function(mocker, cbc_proxy_vodafone):
|
||||
identifier = 'my-identifier'
|
||||
headline = 'my-headline'
|
||||
description = 'my-description'
|
||||
|
||||
sent = 'a-passed-through-sent-value'
|
||||
expires = 'a-passed-through-expires-value'
|
||||
|
||||
# a single area which is a square including london
|
||||
areas = [{
|
||||
'description': 'london',
|
||||
'polygon': [
|
||||
[51.12, -1.2],
|
||||
[51.12, 1.2],
|
||||
[51.74, 1.2],
|
||||
[51.74, -1.2],
|
||||
[51.12, -1.2],
|
||||
],
|
||||
}]
|
||||
|
||||
ld_client_mock = mocker.patch.object(
|
||||
cbc_proxy_vodafone,
|
||||
'_lambda_client',
|
||||
create=True,
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.return_value = {
|
||||
'StatusCode': 200,
|
||||
}
|
||||
|
||||
cbc_proxy_vodafone.create_and_send_broadcast(
|
||||
identifier=identifier,
|
||||
message_number='0000007b',
|
||||
headline=headline,
|
||||
description=description,
|
||||
areas=areas,
|
||||
sent=sent, expires=expires,
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.assert_called_once_with(
|
||||
FunctionName='vodafone-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_number'] == '0000007b'
|
||||
assert payload['message_format'] == 'ibag'
|
||||
assert payload['message_type'] == 'alert'
|
||||
assert payload['headline'] == headline
|
||||
assert payload['description'] == description
|
||||
assert payload['areas'] == areas
|
||||
assert payload['sent'] == sent
|
||||
assert payload['expires'] == expires
|
||||
|
||||
|
||||
def test_cbc_proxy_create_and_send_handles_invoke_error(mocker, cbc_proxy_ee):
|
||||
identifier = 'my-identifier'
|
||||
headline = 'my-headline'
|
||||
@@ -146,7 +210,6 @@ def test_cbc_proxy_create_and_send_handles_invoke_error(mocker, cbc_proxy_ee):
|
||||
cbc_proxy_ee.create_and_send_broadcast(
|
||||
identifier=identifier,
|
||||
message_number='0000007b',
|
||||
message_format='cbc',
|
||||
headline=headline,
|
||||
description=description,
|
||||
areas=areas,
|
||||
@@ -197,7 +260,6 @@ def test_cbc_proxy_create_and_send_handles_function_error(mocker, cbc_proxy_ee):
|
||||
cbc_proxy_ee.create_and_send_broadcast(
|
||||
identifier=identifier,
|
||||
message_number='0000007b',
|
||||
message_format='cbc',
|
||||
headline=headline,
|
||||
description=description,
|
||||
areas=areas,
|
||||
@@ -245,7 +307,7 @@ def test_cbc_proxy_send_canary_invokes_function(mocker, cbc_proxy_client):
|
||||
assert payload['identifier'] == identifier
|
||||
|
||||
|
||||
def test_cbc_proxy_send_link_test_invokes_function(mocker, cbc_proxy_ee):
|
||||
def test_cbc_proxy_ee_send_link_test_invokes_function(mocker, cbc_proxy_ee):
|
||||
identifier = str(uuid.uuid4())
|
||||
|
||||
ld_client_mock = mocker.patch.object(
|
||||
@@ -261,7 +323,6 @@ def test_cbc_proxy_send_link_test_invokes_function(mocker, cbc_proxy_ee):
|
||||
cbc_proxy_ee.send_link_test(
|
||||
identifier=identifier,
|
||||
sequential_number='0000007b',
|
||||
message_format='cbc'
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.assert_called_once_with(
|
||||
@@ -276,5 +337,39 @@ def test_cbc_proxy_send_link_test_invokes_function(mocker, cbc_proxy_ee):
|
||||
|
||||
assert payload['identifier'] == identifier
|
||||
assert payload['message_type'] == 'test'
|
||||
assert payload['message_number'] == '0000007b'
|
||||
assert 'message_number' not in payload
|
||||
assert payload['message_format'] == 'cbc'
|
||||
|
||||
|
||||
def test_cbc_proxy_vodafone_send_link_test_invokes_function(mocker, cbc_proxy_vodafone):
|
||||
identifier = str(uuid.uuid4())
|
||||
|
||||
ld_client_mock = mocker.patch.object(
|
||||
cbc_proxy_vodafone,
|
||||
'_lambda_client',
|
||||
create=True,
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.return_value = {
|
||||
'StatusCode': 200,
|
||||
}
|
||||
|
||||
cbc_proxy_vodafone.send_link_test(
|
||||
identifier=identifier,
|
||||
sequential_number='0000007b',
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.assert_called_once_with(
|
||||
FunctionName='vodafone-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'
|
||||
assert payload['message_number'] == '0000007b'
|
||||
assert payload['message_format'] == 'ibag'
|
||||
|
||||
Reference in New Issue
Block a user