mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-03 21:21:14 -04:00
Merge pull request #3780 from alphagov/show-areas-not-in-library
Display areas that aren’t in the library
This commit is contained in:
@@ -657,6 +657,7 @@ def broadcast_message_json(
|
||||
approved_by_id=None,
|
||||
cancelled_by_id=None,
|
||||
areas=None,
|
||||
simple_polygons=None,
|
||||
content=None,
|
||||
reference=None,
|
||||
template_name='Example template',
|
||||
@@ -676,6 +677,7 @@ def broadcast_message_json(
|
||||
'areas': areas or [
|
||||
'ctry19-E92000001', 'ctry19-S92000003',
|
||||
],
|
||||
'simple_polygons': simple_polygons or [],
|
||||
|
||||
'status': status,
|
||||
|
||||
|
||||
@@ -684,6 +684,53 @@ def test_preview_broadcast_areas_page(
|
||||
] == estimates
|
||||
|
||||
|
||||
def test_preview_broadcast_areas_page_with_custom_polygons(
|
||||
mocker,
|
||||
client_request,
|
||||
service_one,
|
||||
fake_uuid,
|
||||
):
|
||||
service_one['permissions'] += ['broadcast']
|
||||
mocker.patch(
|
||||
'app.broadcast_message_api_client.get_broadcast_message',
|
||||
return_value=broadcast_message_json(
|
||||
id_=fake_uuid,
|
||||
template_id=fake_uuid,
|
||||
created_by_id=fake_uuid,
|
||||
service_id=SERVICE_ONE_ID,
|
||||
status='draft',
|
||||
areas=['Area one', 'Area two', 'Area three'],
|
||||
simple_polygons=[
|
||||
[[1, 2], [3, 4], [5, 6]],
|
||||
[[7, 8], [9, 10], [11, 12]],
|
||||
],
|
||||
),
|
||||
)
|
||||
page = client_request.get(
|
||||
'.preview_broadcast_areas',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
broadcast_message_id=fake_uuid,
|
||||
)
|
||||
|
||||
assert [
|
||||
normalize_spaces(item.text)
|
||||
for item in page.select('ul.area-list li.area-list-item')
|
||||
] == [
|
||||
'Area one remove', 'Area two remove', 'Area three remove',
|
||||
]
|
||||
|
||||
assert len(page.select('#area-list-map')) == 1
|
||||
|
||||
assert [
|
||||
normalize_spaces(item.text)
|
||||
for item in page.select('ul li.area-list-key')
|
||||
] == [
|
||||
'An area of 722.3 square miles Will get the alert',
|
||||
'An extra area of 1,402.5 square miles is Likely to get the alert',
|
||||
'Unknown number of phones',
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('areas, expected_list', (
|
||||
([], [
|
||||
'Countries',
|
||||
@@ -1260,8 +1307,8 @@ def test_start_broadcasting(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('endpoint, extra_fields, expected_paragraphs', (
|
||||
('.view_current_broadcast', {
|
||||
@pytest.mark.parametrize('endpoint, created_by_api, extra_fields, expected_paragraphs', (
|
||||
('.view_current_broadcast', False, {
|
||||
'status': 'broadcasting',
|
||||
'finishes_at': '2020-02-23T23:23:23.000000',
|
||||
}, [
|
||||
@@ -1269,7 +1316,15 @@ def test_start_broadcasting(
|
||||
'Prepared by Alice and approved by Bob.',
|
||||
'Broadcasting stops tomorrow at 11:23pm.'
|
||||
]),
|
||||
('.view_previous_broadcast', {
|
||||
('.view_current_broadcast', True, {
|
||||
'status': 'broadcasting',
|
||||
'finishes_at': '2020-02-23T23:23:23.000000',
|
||||
}, [
|
||||
'Live since 20 February at 8:20pm Stop broadcasting',
|
||||
'Created from an API call and approved by Alice.',
|
||||
'Broadcasting stops tomorrow at 11:23pm.'
|
||||
]),
|
||||
('.view_previous_broadcast', False, {
|
||||
'status': 'broadcasting',
|
||||
'finishes_at': '2020-02-22T22:20:20.000000', # 2 mins before now()
|
||||
}, [
|
||||
@@ -1277,7 +1332,15 @@ def test_start_broadcasting(
|
||||
'Prepared by Alice and approved by Bob.',
|
||||
'Finished broadcasting today at 10:20pm.'
|
||||
]),
|
||||
('.view_previous_broadcast', {
|
||||
('.view_previous_broadcast', True, {
|
||||
'status': 'broadcasting',
|
||||
'finishes_at': '2020-02-22T22:20:20.000000', # 2 mins before now()
|
||||
}, [
|
||||
'Broadcast on 20 February at 8:20pm.',
|
||||
'Created from an API call and approved by Alice.',
|
||||
'Finished broadcasting today at 10:20pm.'
|
||||
]),
|
||||
('.view_previous_broadcast', False, {
|
||||
'status': 'completed',
|
||||
'finishes_at': '2020-02-21T21:21:21.000000',
|
||||
}, [
|
||||
@@ -1285,7 +1348,7 @@ def test_start_broadcasting(
|
||||
'Prepared by Alice and approved by Bob.',
|
||||
'Finished broadcasting yesterday at 9:21pm.',
|
||||
]),
|
||||
('.view_previous_broadcast', {
|
||||
('.view_previous_broadcast', False, {
|
||||
'status': 'cancelled',
|
||||
'cancelled_by_id': sample_uuid,
|
||||
'cancelled_at': '2020-02-21T21:21:21.000000',
|
||||
@@ -1304,6 +1367,7 @@ def test_view_broadcast_message_page(
|
||||
mock_get_broadcast_template,
|
||||
fake_uuid,
|
||||
endpoint,
|
||||
created_by_api,
|
||||
extra_fields,
|
||||
expected_paragraphs,
|
||||
):
|
||||
@@ -1313,7 +1377,7 @@ def test_view_broadcast_message_page(
|
||||
id_=fake_uuid,
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
created_by_id=fake_uuid,
|
||||
created_by_id=None if created_by_api else fake_uuid,
|
||||
approved_by_id=fake_uuid,
|
||||
starts_at='2020-02-20T20:20:20.000000',
|
||||
**extra_fields
|
||||
@@ -1517,6 +1581,49 @@ def test_view_pending_broadcast_without_template(
|
||||
)
|
||||
|
||||
|
||||
@freeze_time('2020-02-22T22:22:22.000000')
|
||||
def test_view_pending_broadcast_from_api_call(
|
||||
mocker,
|
||||
client_request,
|
||||
service_one,
|
||||
active_user_with_permissions,
|
||||
fake_uuid,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.broadcast_message_api_client.get_broadcast_message',
|
||||
return_value=broadcast_message_json(
|
||||
id_=fake_uuid,
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=None,
|
||||
created_by_id=None, # No user created this broadcast
|
||||
finishes_at=None,
|
||||
status='pending-approval',
|
||||
reference='abc123',
|
||||
content='Uh-oh',
|
||||
),
|
||||
)
|
||||
service_one['permissions'] += ['broadcast']
|
||||
|
||||
page = client_request.get(
|
||||
'.view_current_broadcast',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
broadcast_message_id=fake_uuid,
|
||||
)
|
||||
|
||||
assert (
|
||||
normalize_spaces(page.select_one('.banner').text)
|
||||
) == (
|
||||
'An API call wants to broadcast abc123 '
|
||||
'Start broadcasting now Reject this alert'
|
||||
)
|
||||
assert (
|
||||
normalize_spaces(page.select_one('.broadcast-message-wrapper').text)
|
||||
) == (
|
||||
'Emergency alert '
|
||||
'Uh-oh'
|
||||
)
|
||||
|
||||
|
||||
@freeze_time('2020-02-22T22:22:22.000000')
|
||||
def test_cant_approve_own_broadcast(
|
||||
mocker,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from app.models.broadcast_message import BroadcastMessage
|
||||
from tests import broadcast_message_json
|
||||
|
||||
@@ -45,3 +47,24 @@ def test_content_comes_from_attribute_not_template(fake_uuid):
|
||||
created_by_id=fake_uuid,
|
||||
))
|
||||
assert broadcast_message.content == 'This is a test'
|
||||
|
||||
|
||||
def test_raises_for_missing_areas(fake_uuid):
|
||||
broadcast_message = BroadcastMessage(broadcast_message_json(
|
||||
id_=fake_uuid,
|
||||
service_id=fake_uuid,
|
||||
template_id=fake_uuid,
|
||||
status='draft',
|
||||
created_by_id=fake_uuid,
|
||||
areas=[
|
||||
'wd20-E05009372',
|
||||
'something else',
|
||||
],
|
||||
))
|
||||
|
||||
with pytest.raises(RuntimeError) as exception:
|
||||
broadcast_message.areas
|
||||
|
||||
assert str(exception.value) == (
|
||||
'BroadcastMessage has 2 areas but 1 found in the library'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user