mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 16:12:32 -05:00
"areas" and "simple_polygons" in "transmitted_areas" do not have the same length as an example, choosing the area "england" results in a single item in "areas" but many polygons in "simple_polygons" therefore zipping these two together gives a list of areas: * of length 1 * containing only new grimsby which is not what we want as the CBC does not care about the areaDesc field within CAP, we should omit it from the function invocation and delegate the contents of areaDesc to the CBC Proxy implementation Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk> Co-authored-by: Richard <richard.baker@digital.cabinet-office.gov.uk> Co-authored-by: David <david.mcdonald@digital.cabinet-office.gov.uk>
154 lines
5.0 KiB
Python
154 lines
5.0 KiB
Python
from freezegun import freeze_time
|
|
import pytest
|
|
|
|
from app.models import BROADCAST_TYPE, BroadcastStatusType, BroadcastEventMessageType
|
|
from app.celery.broadcast_message_tasks import send_broadcast_event
|
|
from tests.app.db import create_template, create_broadcast_message, create_broadcast_event
|
|
|
|
|
|
@freeze_time('2020-08-01 12:00')
|
|
def test_create_broadcast_event_sends_data_correctly(mocker, sample_service):
|
|
template = create_template(sample_service, BROADCAST_TYPE)
|
|
broadcast_message = create_broadcast_message(
|
|
template,
|
|
areas={
|
|
'areas': ['london', 'glasgow'],
|
|
'simple_polygons': [
|
|
[[50.12, 1.2], [50.13, 1.2], [50.14, 1.21]],
|
|
[[-4.53, 55.72], [-3.88, 55.72], [-3.88, 55.96], [-4.53, 55.96]],
|
|
],
|
|
},
|
|
status=BroadcastStatusType.BROADCASTING
|
|
)
|
|
event = create_broadcast_event(broadcast_message)
|
|
|
|
mock_create_broadcast = mocker.patch(
|
|
'app.cbc_proxy_client.create_and_send_broadcast',
|
|
)
|
|
|
|
send_broadcast_event(broadcast_event_id=str(event.id))
|
|
|
|
mock_create_broadcast.assert_called_once_with(
|
|
identifier=str(event.id),
|
|
headline='GOV.UK Notify Broadcast',
|
|
description='this is an emergency broadcast message',
|
|
areas=[{
|
|
'polygon': [
|
|
[50.12, 1.2], [50.13, 1.2], [50.14, 1.21],
|
|
],
|
|
}, {
|
|
'polygon': [
|
|
[-4.53, 55.72], [-3.88, 55.72], [-3.88, 55.96], [-4.53, 55.96],
|
|
],
|
|
}],
|
|
)
|
|
|
|
|
|
def test_update_broadcast_event_sends_references(mocker, sample_service):
|
|
template = create_template(sample_service, BROADCAST_TYPE, content='content')
|
|
|
|
broadcast_message = create_broadcast_message(
|
|
template,
|
|
areas={
|
|
'areas': ['london'],
|
|
'simple_polygons': [
|
|
[[50.12, 1.2], [50.13, 1.2], [50.14, 1.21]],
|
|
],
|
|
},
|
|
status=BroadcastStatusType.BROADCASTING
|
|
)
|
|
|
|
alert_event = create_broadcast_event(broadcast_message, message_type=BroadcastEventMessageType.ALERT)
|
|
update_event = create_broadcast_event(broadcast_message, message_type=BroadcastEventMessageType.UPDATE)
|
|
|
|
mock_update_broadcast = mocker.patch(
|
|
'app.cbc_proxy_client.update_and_send_broadcast',
|
|
)
|
|
|
|
send_broadcast_event(broadcast_event_id=str(update_event.id))
|
|
|
|
mock_update_broadcast.assert_called_once_with(
|
|
identifier=str(update_event.id),
|
|
headline="GOV.UK Notify Broadcast",
|
|
description='this is an emergency broadcast message',
|
|
areas=[{
|
|
"polygon": [[50.12, 1.2], [50.13, 1.2], [50.14, 1.21]],
|
|
}],
|
|
references=[alert_event.reference],
|
|
)
|
|
|
|
|
|
def test_cancel_broadcast_event_sends_references(mocker, sample_service):
|
|
template = create_template(sample_service, BROADCAST_TYPE, content='content')
|
|
|
|
broadcast_message = create_broadcast_message(
|
|
template,
|
|
areas={
|
|
'areas': ['london'],
|
|
'simple_polygons': [
|
|
[[50.12, 1.2], [50.13, 1.2], [50.14, 1.21]],
|
|
],
|
|
},
|
|
status=BroadcastStatusType.BROADCASTING
|
|
)
|
|
|
|
alert_event = create_broadcast_event(broadcast_message, message_type=BroadcastEventMessageType.ALERT)
|
|
update_event = create_broadcast_event(broadcast_message, message_type=BroadcastEventMessageType.UPDATE)
|
|
cancel_event = create_broadcast_event(broadcast_message, message_type=BroadcastEventMessageType.CANCEL)
|
|
|
|
mock_cancel_broadcast = mocker.patch(
|
|
'app.cbc_proxy_client.cancel_broadcast',
|
|
)
|
|
|
|
send_broadcast_event(broadcast_event_id=str(cancel_event.id))
|
|
|
|
mock_cancel_broadcast.assert_called_once_with(
|
|
identifier=str(cancel_event.id),
|
|
headline="GOV.UK Notify Broadcast",
|
|
description='this is an emergency broadcast message',
|
|
areas=[{
|
|
"polygon": [[50.12, 1.2], [50.13, 1.2], [50.14, 1.21]],
|
|
}],
|
|
references=[alert_event.reference, update_event.reference],
|
|
)
|
|
|
|
|
|
def test_send_broadcast_event_errors(mocker, sample_service):
|
|
template = create_template(sample_service, BROADCAST_TYPE)
|
|
|
|
broadcast_message = create_broadcast_message(
|
|
template,
|
|
areas={
|
|
'areas': ['london'],
|
|
'simple_polygons': [
|
|
[[50.12, 1.2], [50.13, 1.2], [50.14, 1.21]],
|
|
],
|
|
},
|
|
status=BroadcastStatusType.BROADCASTING
|
|
)
|
|
|
|
event = create_broadcast_event(broadcast_message)
|
|
|
|
mock_create_broadcast = mocker.patch(
|
|
'app.cbc_proxy_client.create_and_send_broadcast',
|
|
side_effect=Exception('oh no'),
|
|
)
|
|
|
|
with pytest.raises(Exception) as ex:
|
|
send_broadcast_event(broadcast_event_id=str(event.id))
|
|
|
|
assert ex.match('oh no')
|
|
|
|
mock_create_broadcast.assert_called_once_with(
|
|
identifier=str(event.id),
|
|
headline="GOV.UK Notify Broadcast",
|
|
description='this is an emergency broadcast message',
|
|
areas=[{
|
|
'polygon': [
|
|
[50.12, 1.2],
|
|
[50.13, 1.2],
|
|
[50.14, 1.21],
|
|
],
|
|
}],
|
|
)
|