mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
Mirror integrity checks from the API
It makes sense to have these checks [1] here, since in future we may
add other ways of creating a broadcast event and omit them.
[1]: 3d71815956/app/broadcast_message/rest.py (L198)
This commit is contained in:
@@ -62,6 +62,18 @@ def check_provider_message_should_send(broadcast_event, provider):
|
|||||||
f'to provider {provider}: the service is suspended'
|
f'to provider {provider}: the service is suspended'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if broadcast_event.service.restricted:
|
||||||
|
raise BroadcastIntegrityError(
|
||||||
|
f'Cannot send broadcast_event {broadcast_event.id} ' +
|
||||||
|
f'to provider {provider}: the service is not live'
|
||||||
|
)
|
||||||
|
|
||||||
|
if broadcast_event.broadcast_message.stubbed:
|
||||||
|
raise BroadcastIntegrityError(
|
||||||
|
f'Cannot send broadcast_event {broadcast_event.id} ' +
|
||||||
|
f'to provider {provider}: the broadcast message is stubbed'
|
||||||
|
)
|
||||||
|
|
||||||
current_provider_message = broadcast_event.get_provider_message(provider)
|
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 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:
|
if current_provider_message and current_provider_message.status != BroadcastProviderMessageStatus.SENDING:
|
||||||
|
|||||||
@@ -748,6 +748,31 @@ def test_check_provider_message_should_send_raises_if_service_is_suspended(
|
|||||||
assert 'service is suspended' in str(exc.value)
|
assert 'service is suspended' in str(exc.value)
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_provider_message_should_send_raises_if_service_is_not_live(
|
||||||
|
sample_broadcast_service,
|
||||||
|
):
|
||||||
|
sample_broadcast_service.restricted = True
|
||||||
|
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 not live' in str(exc.value)
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_provider_message_should_send_raises_if_message_is_stubbed(
|
||||||
|
sample_template,
|
||||||
|
):
|
||||||
|
broadcast_message = create_broadcast_message(sample_template, stubbed=True)
|
||||||
|
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 'message is stubbed' in str(exc.value)
|
||||||
|
|
||||||
|
|
||||||
def test_send_broadcast_provider_message_does_nothing_if_cbc_proxy_disabled(mocker, notify_api, sample_template):
|
def test_send_broadcast_provider_message_does_nothing_if_cbc_proxy_disabled(mocker, notify_api, sample_template):
|
||||||
mock_proxy_client_getter = mocker.patch(
|
mock_proxy_client_getter = mocker.patch(
|
||||||
'app.celery.broadcast_message_tasks.cbc_proxy_client',
|
'app.celery.broadcast_message_tasks.cbc_proxy_client',
|
||||||
|
|||||||
Reference in New Issue
Block a user