Allow CBC proxy client to take channel

This moves the hardcoding to test channels one step up to where we call
`create_and_send_broadcast`

We can then after this, start to differ whether we give it the 'test' or
'severe' channel based on the services channel setting.
This commit is contained in:
David McDonald
2021-01-29 11:54:12 +00:00
parent 91f5be835a
commit 2aad3163e6
4 changed files with 27 additions and 13 deletions

View File

@@ -59,6 +59,7 @@ def send_broadcast_provider_message(broadcast_event_id, provider):
areas=areas,
sent=broadcast_event.sent_at_as_cap_datetime_string,
expires=broadcast_event.transmitted_finishes_at_as_cap_datetime_string,
channel="test"
)
elif broadcast_event.message_type == BroadcastEventMessageType.UPDATE:
cbc_proxy_provider_client.update_and_send_broadcast(
@@ -70,6 +71,7 @@ def send_broadcast_provider_message(broadcast_event_id, provider):
previous_provider_messages=broadcast_event.get_earlier_provider_messages(provider),
sent=broadcast_event.sent_at_as_cap_datetime_string,
expires=broadcast_event.transmitted_finishes_at_as_cap_datetime_string,
channel="test"
)
elif broadcast_event.message_type == BroadcastEventMessageType.CANCEL:
cbc_proxy_provider_client.cancel_broadcast(

View File

@@ -90,7 +90,7 @@ class CBCProxyClientBase(ABC):
pass
def create_and_send_broadcast(
self, identifier, headline, description, areas, sent, expires, message_number=None
self, identifier, headline, description, areas, sent, expires, channel, message_number=None
):
pass
@@ -98,7 +98,7 @@ class CBCProxyClientBase(ABC):
def update_and_send_broadcast(
self,
identifier, previous_provider_messages, headline, description, areas,
sent, expires, message_number=None
sent, expires, channel, message_number=None
):
pass
@@ -198,7 +198,7 @@ class CBCProxyEE(CBCProxyClientBase):
self._invoke_lambda_with_failover(payload=payload)
def create_and_send_broadcast(
self, identifier, headline, description, areas, sent, expires, message_number=None
self, identifier, headline, description, areas, sent, expires, channel, message_number=None
):
payload = {
'message_type': 'alert',
@@ -210,7 +210,7 @@ class CBCProxyEE(CBCProxyClientBase):
'sent': sent,
'expires': expires,
'language': self.infer_language_from(description),
'channel': 'test',
'channel': channel,
}
self._invoke_lambda_with_failover(payload=payload)
@@ -259,7 +259,7 @@ class CBCProxyThree(CBCProxyClientBase):
self._invoke_lambda_with_failover(payload=payload)
def create_and_send_broadcast(
self, identifier, headline, description, areas, sent, expires, message_number=None
self, identifier, headline, description, areas, sent, expires, channel, message_number=None
):
payload = {
'message_type': 'alert',
@@ -271,7 +271,7 @@ class CBCProxyThree(CBCProxyClientBase):
'sent': sent,
'expires': expires,
'language': self.infer_language_from(description),
'channel': 'test',
'channel': channel,
}
self._invoke_lambda_with_failover(payload=payload)
@@ -319,7 +319,7 @@ class CBCProxyO2(CBCProxyClientBase):
self._invoke_lambda_with_failover(payload=payload)
def create_and_send_broadcast(
self, identifier, headline, description, areas, sent, expires, message_number=None
self, identifier, headline, description, areas, sent, expires, channel, message_number=None
):
payload = {
'message_type': 'alert',
@@ -331,7 +331,7 @@ class CBCProxyO2(CBCProxyClientBase):
'sent': sent,
'expires': expires,
'language': self.infer_language_from(description),
'channel': 'test',
'channel': channel,
}
self._invoke_lambda_with_failover(payload=payload)
@@ -381,7 +381,7 @@ class CBCProxyVodafone(CBCProxyClientBase):
self._invoke_lambda_with_failover(payload=payload)
def create_and_send_broadcast(
self, identifier, message_number, headline, description, areas, sent, expires,
self, identifier, message_number, headline, description, areas, sent, expires, channel
):
payload = {
'message_type': 'alert',
@@ -394,7 +394,7 @@ class CBCProxyVodafone(CBCProxyClientBase):
'sent': sent,
'expires': expires,
'language': self.infer_language_from(description),
'channel': 'test',
'channel': channel,
}
self._invoke_lambda_with_failover(payload=payload)

View File

@@ -153,6 +153,7 @@ def test_send_broadcast_provider_message_sends_data_correctly(
}],
sent=event.sent_at_as_cap_datetime_string,
expires=event.transmitted_finishes_at_as_cap_datetime_string,
channel="test",
)
@@ -191,6 +192,7 @@ def test_send_broadcast_provider_message_sends_data_correctly_when_broadcast_mes
areas=mocker.ANY,
sent=mocker.ANY,
expires=mocker.ANY,
channel="test"
)
@@ -240,6 +242,7 @@ def test_send_broadcast_provider_message_sends_update_with_references(
],
sent=update_event.sent_at_as_cap_datetime_string,
expires=update_event.transmitted_finishes_at_as_cap_datetime_string,
channel="test"
)
@@ -330,6 +333,7 @@ def test_send_broadcast_provider_message_errors(mocker, sample_service):
}],
sent=event.sent_at_as_cap_datetime_string,
expires=event.transmitted_finishes_at_as_cap_datetime_string,
channel="test"
)

View File

@@ -110,7 +110,9 @@ def test_cbc_proxy_one_2_many_create_and_send_invokes_function(
headline=headline,
description=description,
areas=EXAMPLE_AREAS,
sent=sent, expires=expires,
sent=sent,
expires=expires,
channel="severe",
)
ld_client_mock.invoke.assert_called_once_with(
@@ -133,7 +135,7 @@ def test_cbc_proxy_one_2_many_create_and_send_invokes_function(
assert payload['sent'] == sent
assert payload['expires'] == expires
assert payload['language'] == expected_language
assert payload['channel'] == 'test'
assert payload['channel'] == 'severe'
@pytest.mark.parametrize('cbc', ['ee', 'three', 'o2'])
@@ -227,7 +229,9 @@ def test_cbc_proxy_vodafone_create_and_send_invokes_function(
headline=headline,
description=description,
areas=EXAMPLE_AREAS,
sent=sent, expires=expires,
sent=sent,
expires=expires,
channel="test",
)
ld_client_mock.invoke.assert_called_once_with(
@@ -348,6 +352,7 @@ def test_cbc_proxy_will_failover_to_second_lambda_if_function_error(
areas=EXAMPLE_AREAS,
sent='a-passed-through-sent-value',
expires='a-passed-through-expires-value',
channel="severe",
)
assert ld_client_mock.invoke.call_args_list == [
@@ -395,6 +400,7 @@ def test_cbc_proxy_will_failover_to_second_lambda_if_invoke_error(
areas=EXAMPLE_AREAS,
sent='a-passed-through-sent-value',
expires='a-passed-through-expires-value',
channel="test",
)
assert ld_client_mock.invoke.call_args_list == [
@@ -436,6 +442,7 @@ def test_cbc_proxy_create_and_send_tries_failover_lambda_on_invoke_error_and_rai
areas=EXAMPLE_AREAS,
sent='a-passed-through-sent-value',
expires='a-passed-through-expires-value',
channel="test",
)
assert e.match(f'Lambda failed for both {cbc}-1-proxy and {cbc}-2-proxy')
@@ -484,6 +491,7 @@ def test_cbc_proxy_create_and_send_tries_failover_lambda_on_function_error_and_r
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')