Move CBC proxy enable check

This change will make our development environments closer to production
even if they aren't hooked up to the CBC proxy lambda functions.

Now in development, we will create the broadcast event and create tasks
for each broadcast provider event. We will still not create actual
broadcast provider message rows in the DB and talk to the CBC proxies.

This should be helpful in development to catch any issues we introduce
to do with sending broadcast messaging. In time we may wish to have some
fake CBC proxies in the AWS tools account that we can interact with to
make it even more realistic.
This commit is contained in:
David McDonald
2021-04-12 15:17:59 +01:00
parent 514afeb6f3
commit 295162c81d
2 changed files with 23 additions and 17 deletions

View File

@@ -106,10 +106,6 @@ def check_provider_message_should_send(broadcast_event, provider):
@notify_celery.task(name="send-broadcast-event") @notify_celery.task(name="send-broadcast-event")
@statsd(namespace="tasks") @statsd(namespace="tasks")
def send_broadcast_event(broadcast_event_id): def send_broadcast_event(broadcast_event_id):
if not current_app.config['CBC_PROXY_ENABLED']:
current_app.logger.info(f'CBC Proxy disabled, not sending broadcast_event {broadcast_event_id}')
return
broadcast_event = dao_get_broadcast_event_by_id(broadcast_event_id) broadcast_event = dao_get_broadcast_event_by_id(broadcast_event_id)
if ( if (
@@ -149,6 +145,13 @@ def send_broadcast_event(broadcast_event_id):
@notify_celery.task(bind=True, name="send-broadcast-provider-message", max_retries=None) @notify_celery.task(bind=True, name="send-broadcast-provider-message", max_retries=None)
@statsd(namespace="tasks") @statsd(namespace="tasks")
def send_broadcast_provider_message(self, broadcast_event_id, provider): def send_broadcast_provider_message(self, broadcast_event_id, provider):
if not current_app.config['CBC_PROXY_ENABLED']:
current_app.logger.info(
"CBC Proxy disabled, not sending broadcast_provider_message for "
f"broadcast_event_id {broadcast_event_id} with provider {provider}"
)
return
broadcast_event = dao_get_broadcast_event_by_id(broadcast_event_id) broadcast_event = dao_get_broadcast_event_by_id(broadcast_event_id)
check_provider_message_should_send(broadcast_event, provider) check_provider_message_should_send(broadcast_event, provider)

View File

@@ -1,6 +1,6 @@
import uuid import uuid
from datetime import datetime from datetime import datetime
from unittest.mock import ANY, call from unittest.mock import ANY, Mock, call
import pytest import pytest
from celery.exceptions import Retry from celery.exceptions import Retry
@@ -98,18 +98,6 @@ def test_send_broadcast_event_does_nothing_if_provider_set_on_service_isnt_enabl
assert mock_send_broadcast_provider_message.apply_async.called is False assert mock_send_broadcast_provider_message.apply_async.called is False
def test_send_broadcast_event_does_nothing_if_cbc_proxy_disabled(mocker, notify_api):
mock_send_broadcast_provider_message = mocker.patch(
'app.celery.broadcast_message_tasks.send_broadcast_provider_message',
)
event_id = uuid.uuid4()
with set_config(notify_api, 'ENABLED_CBCS', ['ee', 'vodafone']), set_config(notify_api, 'CBC_PROXY_ENABLED', False):
send_broadcast_event(event_id)
assert mock_send_broadcast_provider_message.apply_async.called is False
def test_send_broadcast_event_creates_zendesk_p1(mocker, notify_api, sample_broadcast_service): def test_send_broadcast_event_creates_zendesk_p1(mocker, notify_api, sample_broadcast_service):
template = create_template(sample_broadcast_service, BROADCAST_TYPE) template = create_template(sample_broadcast_service, BROADCAST_TYPE)
broadcast_message = create_broadcast_message( broadcast_message = create_broadcast_message(
@@ -747,3 +735,18 @@ def test_check_provider_message_should_send_raises_if_current_event_already_has_
create_broadcast_provider_message(current_event, provider='ee', status=existing_message_status) create_broadcast_provider_message(current_event, provider='ee', status=existing_message_status)
check_provider_message_should_send(current_event, 'ee') check_provider_message_should_send(current_event, 'ee')
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',
)
mock_client = Mock()
mock_proxy_client_getter.get_proxy.return_value = mock_client
broadcast_message = create_broadcast_message(sample_template)
broadcast_event = create_broadcast_event(broadcast_message, message_type='alert')
with set_config(notify_api, 'ENABLED_CBCS', ['ee', 'vodafone']), set_config(notify_api, 'CBC_PROXY_ENABLED', False):
send_broadcast_provider_message(broadcast_event.id, 'ee')
assert mock_client.create_and_send_broadcast.called is False