mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
move BroadcastProvider from models.py to config.py
It's not something that is tied to a database table, and was causing circular import issues
This commit is contained in:
@@ -1,13 +1,33 @@
|
||||
import uuid
|
||||
from unittest.mock import call
|
||||
|
||||
from freezegun import freeze_time
|
||||
import pytest
|
||||
|
||||
from app.models import BROADCAST_TYPE, BroadcastStatusType, BroadcastEventMessageType
|
||||
from app.celery.broadcast_message_tasks import send_broadcast_event
|
||||
from app.celery.broadcast_message_tasks import send_broadcast_event, send_broadcast_provider_message, trigger_link_test
|
||||
|
||||
from tests.app.db import create_template, create_broadcast_message, create_broadcast_event
|
||||
from tests.conftest import set_config
|
||||
|
||||
|
||||
def test_send_broadcast_event_queues_up_for_active_providers(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']):
|
||||
send_broadcast_event(event_id)
|
||||
|
||||
assert mock_send_broadcast_provider_message.apply_async.call_args_list == [
|
||||
call(kwargs={'broadcast_event_id': event_id, 'provider': 'ee'}, queue='notify-internal-tasks'),
|
||||
call(kwargs={'broadcast_event_id': event_id, 'provider': 'vodafone'}, queue='notify-internal-tasks')
|
||||
]
|
||||
|
||||
|
||||
@freeze_time('2020-08-01 12:00')
|
||||
def test_create_broadcast_event_sends_data_correctly(mocker, sample_service):
|
||||
def test_send_broadcast_provider_message_sends_data_correctly(mocker, sample_service):
|
||||
template = create_template(sample_service, BROADCAST_TYPE)
|
||||
broadcast_message = create_broadcast_message(
|
||||
template,
|
||||
@@ -26,7 +46,7 @@ def test_create_broadcast_event_sends_data_correctly(mocker, sample_service):
|
||||
'app.cbc_proxy_client.create_and_send_broadcast',
|
||||
)
|
||||
|
||||
send_broadcast_event(broadcast_event_id=str(event.id))
|
||||
send_broadcast_provider_message(provider='ee', broadcast_event_id=str(event.id))
|
||||
|
||||
mock_create_broadcast.assert_called_once_with(
|
||||
identifier=str(event.id),
|
||||
@@ -46,7 +66,7 @@ def test_create_broadcast_event_sends_data_correctly(mocker, sample_service):
|
||||
)
|
||||
|
||||
|
||||
def test_update_broadcast_event_sends_references(mocker, sample_service):
|
||||
def test_send_broadcast_provider_message_sends_update_with_references(mocker, sample_service):
|
||||
template = create_template(sample_service, BROADCAST_TYPE, content='content')
|
||||
|
||||
broadcast_message = create_broadcast_message(
|
||||
@@ -67,7 +87,7 @@ def test_update_broadcast_event_sends_references(mocker, sample_service):
|
||||
'app.cbc_proxy_client.update_and_send_broadcast',
|
||||
)
|
||||
|
||||
send_broadcast_event(broadcast_event_id=str(update_event.id))
|
||||
send_broadcast_provider_message(provider='ee', broadcast_event_id=str(update_event.id))
|
||||
|
||||
mock_update_broadcast.assert_called_once_with(
|
||||
identifier=str(update_event.id),
|
||||
@@ -82,7 +102,7 @@ def test_update_broadcast_event_sends_references(mocker, sample_service):
|
||||
)
|
||||
|
||||
|
||||
def test_cancel_broadcast_event_sends_references(mocker, sample_service):
|
||||
def test_send_broadcast_provider_message_sends_cancel_with_references(mocker, sample_service):
|
||||
template = create_template(sample_service, BROADCAST_TYPE, content='content')
|
||||
|
||||
broadcast_message = create_broadcast_message(
|
||||
@@ -104,7 +124,7 @@ def test_cancel_broadcast_event_sends_references(mocker, sample_service):
|
||||
'app.cbc_proxy_client.cancel_broadcast',
|
||||
)
|
||||
|
||||
send_broadcast_event(broadcast_event_id=str(cancel_event.id))
|
||||
send_broadcast_provider_message(provider='ee', broadcast_event_id=str(cancel_event.id))
|
||||
|
||||
mock_cancel_broadcast.assert_called_once_with(
|
||||
identifier=str(cancel_event.id),
|
||||
@@ -119,7 +139,7 @@ def test_cancel_broadcast_event_sends_references(mocker, sample_service):
|
||||
)
|
||||
|
||||
|
||||
def test_send_broadcast_event_errors(mocker, sample_service):
|
||||
def test_send_broadcast_provider_message_errors(mocker, sample_service):
|
||||
template = create_template(sample_service, BROADCAST_TYPE)
|
||||
|
||||
broadcast_message = create_broadcast_message(
|
||||
@@ -141,7 +161,7 @@ def test_send_broadcast_event_errors(mocker, sample_service):
|
||||
)
|
||||
|
||||
with pytest.raises(Exception) as ex:
|
||||
send_broadcast_event(broadcast_event_id=str(event.id))
|
||||
send_broadcast_provider_message(provider='ee', broadcast_event_id=str(event.id))
|
||||
|
||||
assert ex.match('oh no')
|
||||
|
||||
@@ -159,3 +179,22 @@ def test_send_broadcast_event_errors(mocker, sample_service):
|
||||
sent=event.sent_at_as_cap_datetime_string,
|
||||
expires=event.transmitted_finishes_at_as_cap_datetime_string,
|
||||
)
|
||||
|
||||
|
||||
def test_trigger_link_tests_invokes_cbc_proxy_client(
|
||||
mocker,
|
||||
):
|
||||
mock_send_link_test = mocker.patch(
|
||||
'app.cbc_proxy_client.send_link_test',
|
||||
)
|
||||
|
||||
trigger_link_test('some-provider')
|
||||
|
||||
assert mock_send_link_test.called
|
||||
# the 0th argument of the call to send_link_test
|
||||
identifier = mock_send_link_test.mock_calls[0][1][0]
|
||||
|
||||
try:
|
||||
uuid.UUID(identifier)
|
||||
except BaseException:
|
||||
pytest.fail(f"{identifier} is not a valid uuid")
|
||||
|
||||
@@ -19,6 +19,7 @@ from app.celery.scheduled_tasks import (
|
||||
check_for_missing_rows_in_completed_jobs,
|
||||
check_for_services_with_high_failure_rates_or_sending_to_tv_numbers,
|
||||
switch_current_sms_provider_on_slow_delivery,
|
||||
trigger_link_tests,
|
||||
)
|
||||
from app.config import QueueNames, Config
|
||||
from app.dao.jobs_dao import dao_get_job_by_id
|
||||
@@ -30,8 +31,8 @@ from app.models import (
|
||||
NOTIFICATION_DELIVERED,
|
||||
NOTIFICATION_PENDING_VIRUS_CHECK,
|
||||
)
|
||||
from tests.conftest import set_config
|
||||
from tests.app import load_example_csv
|
||||
|
||||
from tests.app.db import (
|
||||
create_notification,
|
||||
create_template,
|
||||
@@ -577,20 +578,17 @@ def test_send_canary_to_cbc_proxy_invokes_cbc_proxy_client(
|
||||
pytest.fail(f"{identifier} is not a valid uuid")
|
||||
|
||||
|
||||
def test_trigger_link_tests_invokes_cbc_proxy_client(
|
||||
mocker,
|
||||
def test_trigger_link_tests_calls_for_all_providers(
|
||||
mocker, notify_api
|
||||
):
|
||||
mock_send_link_test = mocker.patch(
|
||||
'app.cbc_proxy_client.send_link_test',
|
||||
mock_trigger_link_test = mocker.patch(
|
||||
'app.celery.scheduled_tasks.trigger_link_test',
|
||||
)
|
||||
|
||||
scheduled_tasks.trigger_link_tests()
|
||||
with set_config(notify_api, 'ENABLED_CBCS', ['ee', 'vodafone']):
|
||||
trigger_link_tests()
|
||||
|
||||
mock_send_link_test.assert_called
|
||||
# the 0th argument of the call to send_link_test
|
||||
identifier = mock_send_link_test.mock_calls[0][1][0]
|
||||
|
||||
try:
|
||||
uuid.UUID(identifier)
|
||||
except BaseException:
|
||||
pytest.fail(f"{identifier} is not a valid uuid")
|
||||
assert mock_trigger_link_test.apply_async.call_args_list == [
|
||||
call(kwargs={'provider': 'ee'}, queue='notify-internal-tasks'),
|
||||
call(kwargs={'provider': 'vodafone'}, queue='notify-internal-tasks')
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user