mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
Check for suspension before sending a broadcast
This mirrors the check we do for jobs, which are also a high-impact
task [1]. While this shouldn't be possible, just like other checks
we're adding it here to be doubly certain.
[1]: 3d71815956/app/celery/tasks.py (L74)
This commit is contained in:
@@ -56,6 +56,12 @@ def check_provider_message_should_send(broadcast_event, provider):
|
||||
4. If you need to re-send this task off again, you'll need to run the following command on paas:
|
||||
`send_broadcast_provider_message.apply_async(args=(broadcast_event_id, provider), queue=QueueNames.BROADCASTS)`
|
||||
"""
|
||||
if not broadcast_event.service.active:
|
||||
raise BroadcastIntegrityError(
|
||||
f'Cannot send broadcast_event {broadcast_event.id} ' +
|
||||
f'to provider {provider}: the service is suspended'
|
||||
)
|
||||
|
||||
current_provider_message = broadcast_event.get_provider_message(provider)
|
||||
# if this is the first time a task is being executed, it won't have a provider message yet
|
||||
if current_provider_message and current_provider_message.status != BroadcastProviderMessageStatus.SENDING:
|
||||
|
||||
@@ -735,6 +735,19 @@ def test_check_provider_message_should_send_raises_if_current_event_already_has_
|
||||
check_provider_message_should_send(current_event, 'ee')
|
||||
|
||||
|
||||
def test_check_provider_message_should_send_raises_if_service_is_suspended(
|
||||
sample_broadcast_service,
|
||||
):
|
||||
sample_broadcast_service.active = False
|
||||
broadcast_message = create_broadcast_message(service=sample_broadcast_service, content='test')
|
||||
current_event = create_broadcast_event(broadcast_message, message_type='alert')
|
||||
|
||||
with pytest.raises(BroadcastIntegrityError) as exc:
|
||||
check_provider_message_should_send(current_event, 'ee')
|
||||
|
||||
assert 'service is suspended' in str(exc.value)
|
||||
|
||||
|
||||
def test_send_broadcast_provider_message_does_nothing_if_cbc_proxy_disabled(mocker, notify_api, sample_template):
|
||||
mock_proxy_client_getter = mocker.patch(
|
||||
'app.celery.broadcast_message_tasks.cbc_proxy_client',
|
||||
|
||||
Reference in New Issue
Block a user