mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 06:11:49 -05:00
clients: cbc_proxy actions accepts areas param
related: https://github.com/alphagov/notifications-broadcasts-infra/pull/23 Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
This commit is contained in:
@@ -20,10 +20,19 @@ def send_broadcast_event(broadcast_event_id, provider='stub-1'):
|
|||||||
f'msgType {broadcast_event.message_type} to {provider}'
|
f'msgType {broadcast_event.message_type} to {provider}'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
areas = [
|
||||||
|
{"description": desc, "polygon": polygon}
|
||||||
|
for desc, polygon in zip(
|
||||||
|
broadcast_event.transmitted_areas["areas"],
|
||||||
|
broadcast_event.transmitted_areas["simple_polygons"],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
cbc_proxy_client.create_and_send_broadcast(
|
cbc_proxy_client.create_and_send_broadcast(
|
||||||
identifier=str(broadcast_event.id),
|
identifier=str(broadcast_event.id),
|
||||||
headline="GOV.UK Notify Broadcast",
|
headline="GOV.UK Notify Broadcast",
|
||||||
description=broadcast_event.transmitted_content['body'],
|
description=broadcast_event.transmitted_content['body'],
|
||||||
|
areas=areas,
|
||||||
)
|
)
|
||||||
|
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ import boto3
|
|||||||
# headline is a field which we are not sure if we will use
|
# headline is a field which we are not sure if we will use
|
||||||
#
|
#
|
||||||
# description is the body of the message
|
# description is the body of the message
|
||||||
|
|
||||||
|
# areas is a list of dicts, with the following items
|
||||||
|
# * description is a string which populates the areaDesc field
|
||||||
|
# * polygon is a list of lat/long pairs
|
||||||
#
|
#
|
||||||
# references is a whitespace separated list of message identifiers
|
# references is a whitespace separated list of message identifiers
|
||||||
# where each identifier is a previous sent message
|
# where each identifier is a previous sent message
|
||||||
@@ -24,21 +28,21 @@ class CBCProxyNoopClient:
|
|||||||
|
|
||||||
def create_and_send_broadcast(
|
def create_and_send_broadcast(
|
||||||
self,
|
self,
|
||||||
identifier, headline, description,
|
identifier, headline, description, areas
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# We have not implementated updating a broadcast
|
# We have not implementated updating a broadcast
|
||||||
def update_and_send_broadcast(
|
def update_and_send_broadcast(
|
||||||
self,
|
self,
|
||||||
identifier, references, headline, description,
|
identifier, references, headline, description, areas
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# We have not implemented cancelling a broadcast
|
# We have not implemented cancelling a broadcast
|
||||||
def cancel_broadcast(
|
def cancel_broadcast(
|
||||||
self,
|
self,
|
||||||
identifier, references, headline, description,
|
identifier, references, headline, description, areas
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -55,12 +59,13 @@ class CBCProxyClient:
|
|||||||
|
|
||||||
def create_and_send_broadcast(
|
def create_and_send_broadcast(
|
||||||
self,
|
self,
|
||||||
identifier, headline, description,
|
identifier, headline, description, areas,
|
||||||
):
|
):
|
||||||
payload_bytes = bytes(json.dumps({
|
payload_bytes = bytes(json.dumps({
|
||||||
'identifier': identifier,
|
'identifier': identifier,
|
||||||
'headline': headline,
|
'headline': headline,
|
||||||
'description': description,
|
'description': description,
|
||||||
|
'areas': areas,
|
||||||
}), encoding='utf8')
|
}), encoding='utf8')
|
||||||
|
|
||||||
result = self._lambda_client.invoke(
|
result = self._lambda_client.invoke(
|
||||||
@@ -78,13 +83,13 @@ class CBCProxyClient:
|
|||||||
# We have not implementated updating a broadcast
|
# We have not implementated updating a broadcast
|
||||||
def update_and_send_broadcast(
|
def update_and_send_broadcast(
|
||||||
self,
|
self,
|
||||||
identifier, references, headline, description,
|
identifier, references, headline, description, areas,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# We have not implemented cancelling a broadcast
|
# We have not implemented cancelling a broadcast
|
||||||
def cancel_broadcast(
|
def cancel_broadcast(
|
||||||
self,
|
self,
|
||||||
identifier, references, headline, description,
|
identifier, references, headline, description, areas,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ def test_send_broadcast_event_sends_data_correctly(mocker, sample_service):
|
|||||||
identifier=str(event.id),
|
identifier=str(event.id),
|
||||||
headline="GOV.UK Notify Broadcast",
|
headline="GOV.UK Notify Broadcast",
|
||||||
description='this is an emergency broadcast message',
|
description='this is an emergency broadcast message',
|
||||||
|
areas=[{
|
||||||
|
"description": "london",
|
||||||
|
"polygon": [[50.12, 1.2], [50.13, 1.2], [50.14, 1.21]],
|
||||||
|
}]
|
||||||
)
|
)
|
||||||
|
|
||||||
assert request_mock.call_count == 1
|
assert request_mock.call_count == 1
|
||||||
@@ -93,4 +97,12 @@ def test_send_broadcast_event_errors(mocker, sample_service):
|
|||||||
identifier=str(event.id),
|
identifier=str(event.id),
|
||||||
headline="GOV.UK Notify Broadcast",
|
headline="GOV.UK Notify Broadcast",
|
||||||
description='this is an emergency broadcast message',
|
description='this is an emergency broadcast message',
|
||||||
|
areas=[{
|
||||||
|
'description': 'london',
|
||||||
|
'polygon': [
|
||||||
|
[50.12, 1.2],
|
||||||
|
[50.13, 1.2],
|
||||||
|
[50.14, 1.21],
|
||||||
|
],
|
||||||
|
}],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -33,6 +33,18 @@ def test_cbc_proxy_create_and_send_invokes_function(mocker, cbc_proxy):
|
|||||||
headline = 'my-headline'
|
headline = 'my-headline'
|
||||||
description = 'my-description'
|
description = 'my-description'
|
||||||
|
|
||||||
|
# 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(
|
ld_client_mock = mocker.patch.object(
|
||||||
cbc_proxy,
|
cbc_proxy,
|
||||||
'_lambda_client',
|
'_lambda_client',
|
||||||
@@ -47,6 +59,7 @@ def test_cbc_proxy_create_and_send_invokes_function(mocker, cbc_proxy):
|
|||||||
identifier=identifier,
|
identifier=identifier,
|
||||||
headline=headline,
|
headline=headline,
|
||||||
description=description,
|
description=description,
|
||||||
|
areas=areas,
|
||||||
)
|
)
|
||||||
|
|
||||||
ld_client_mock.invoke.assert_called_once_with(
|
ld_client_mock.invoke.assert_called_once_with(
|
||||||
@@ -62,6 +75,7 @@ def test_cbc_proxy_create_and_send_invokes_function(mocker, cbc_proxy):
|
|||||||
assert payload['identifier'] == identifier
|
assert payload['identifier'] == identifier
|
||||||
assert payload['headline'] == headline
|
assert payload['headline'] == headline
|
||||||
assert payload['description'] == description
|
assert payload['description'] == description
|
||||||
|
assert payload['areas'] == areas
|
||||||
|
|
||||||
|
|
||||||
def test_cbc_proxy_create_and_send_handles_invoke_error(mocker, cbc_proxy):
|
def test_cbc_proxy_create_and_send_handles_invoke_error(mocker, cbc_proxy):
|
||||||
@@ -69,6 +83,18 @@ def test_cbc_proxy_create_and_send_handles_invoke_error(mocker, cbc_proxy):
|
|||||||
headline = 'my-headline'
|
headline = 'my-headline'
|
||||||
description = 'my-description'
|
description = 'my-description'
|
||||||
|
|
||||||
|
# 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(
|
ld_client_mock = mocker.patch.object(
|
||||||
cbc_proxy,
|
cbc_proxy,
|
||||||
'_lambda_client',
|
'_lambda_client',
|
||||||
@@ -84,6 +110,7 @@ def test_cbc_proxy_create_and_send_handles_invoke_error(mocker, cbc_proxy):
|
|||||||
identifier=identifier,
|
identifier=identifier,
|
||||||
headline=headline,
|
headline=headline,
|
||||||
description=description,
|
description=description,
|
||||||
|
areas=areas,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert e.match('Could not invoke lambda')
|
assert e.match('Could not invoke lambda')
|
||||||
@@ -100,6 +127,18 @@ def test_cbc_proxy_create_and_send_handles_function_error(mocker, cbc_proxy):
|
|||||||
headline = 'my-headline'
|
headline = 'my-headline'
|
||||||
description = 'my-description'
|
description = 'my-description'
|
||||||
|
|
||||||
|
# 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(
|
ld_client_mock = mocker.patch.object(
|
||||||
cbc_proxy,
|
cbc_proxy,
|
||||||
'_lambda_client',
|
'_lambda_client',
|
||||||
@@ -116,6 +155,7 @@ def test_cbc_proxy_create_and_send_handles_function_error(mocker, cbc_proxy):
|
|||||||
identifier=identifier,
|
identifier=identifier,
|
||||||
headline=headline,
|
headline=headline,
|
||||||
description=description,
|
description=description,
|
||||||
|
areas=areas,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert e.match('Function exited with unhandled exception')
|
assert e.match('Function exited with unhandled exception')
|
||||||
|
|||||||
Reference in New Issue
Block a user