mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Check if a service is live before sending a broadcast
We only want to send a broadcast if the broadcast message is not stubbed and the service is live at the point at which the broadcast event should be created. This is to prevent the situation where a broadcast service is switched to live / trial mode in between the message being created and approved (we log an error if this happens). A stubbed broadcast message with a trial mode service at the point of approval is not an issue - trial mode services can approve their own broadcasts. In this situation, we don't create the broadcast event but also don't need to log an error.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import uuid
|
||||
from unittest.mock import ANY
|
||||
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
@@ -562,23 +561,32 @@ def test_update_broadcast_message_status_stores_approved_by_and_approved_at_and_
|
||||
assert alert_event.transmitted_content == {"body": "emergency broadcast"}
|
||||
|
||||
|
||||
def test_update_broadcast_message_status_updates_details_but_does_not_queue_task_for_stubbed_broadcast_message(
|
||||
@pytest.mark.parametrize('broadcast_message_stubbed, service_restricted_before_approval', [
|
||||
(True, True),
|
||||
(True, False),
|
||||
(False, True),
|
||||
])
|
||||
def test_update_broadcast_message_status_updates_details_but_does_not_queue_task_if_bm_is_stubbed_or_service_not_live(
|
||||
admin_request,
|
||||
sample_broadcast_service,
|
||||
mocker
|
||||
mocker,
|
||||
broadcast_message_stubbed,
|
||||
service_restricted_before_approval,
|
||||
):
|
||||
sample_broadcast_service.restricted = True
|
||||
sample_broadcast_service.restricted = broadcast_message_stubbed
|
||||
t = create_template(sample_broadcast_service, BROADCAST_TYPE, content='emergency broadcast')
|
||||
bm = create_broadcast_message(
|
||||
t,
|
||||
status=BroadcastStatusType.PENDING_APPROVAL,
|
||||
areas={"areas": ["london"], "simple_polygons": [[[51.30, 0.7], [51.28, 0.8], [51.25, -0.7]]]},
|
||||
stubbed=True
|
||||
stubbed=broadcast_message_stubbed
|
||||
)
|
||||
approver = create_user(email='approver@gov.uk')
|
||||
sample_broadcast_service.users.append(approver)
|
||||
mock_task = mocker.patch('app.celery.broadcast_message_tasks.send_broadcast_event.apply_async')
|
||||
|
||||
sample_broadcast_service.restricted = service_restricted_before_approval
|
||||
|
||||
response = admin_request.post(
|
||||
'broadcast_message.update_broadcast_message_status',
|
||||
_data={'status': BroadcastStatusType.BROADCASTING, 'created_by': str(approver.id)},
|
||||
@@ -707,7 +715,7 @@ def test_update_broadcast_message_status_allows_trial_mode_services_to_approve_o
|
||||
assert response['approved_at'] is not None
|
||||
assert response['created_by_id'] == str(t.created_by_id)
|
||||
assert response['approved_by_id'] == str(t.created_by_id)
|
||||
mock_task.assert_called_once_with(kwargs={'broadcast_event_id': ANY}, queue='broadcast-tasks')
|
||||
assert not mock_task.called
|
||||
|
||||
|
||||
def test_update_broadcast_message_status_rejects_approval_from_user_not_on_that_service(
|
||||
|
||||
Reference in New Issue
Block a user