Merge pull request #2201 from alphagov/one-off-letters-from-admin-app

Allow the admin app to send one-off letters
This commit is contained in:
Chris Hill-Scott
2018-11-01 11:40:48 +00:00
committed by GitHub
4 changed files with 65 additions and 21 deletions

View File

@@ -257,22 +257,35 @@ def test_persist_notification_increments_cache_if_key_exists(sample_template, sa
]
@pytest.mark.parametrize('research_mode, requested_queue, expected_queue, notification_type, key_type',
[(True, None, 'research-mode-tasks', 'sms', 'normal'),
(True, None, 'research-mode-tasks', 'email', 'normal'),
(True, None, 'research-mode-tasks', 'email', 'team'),
(False, None, 'send-sms-tasks', 'sms', 'normal'),
(False, None, 'send-email-tasks', 'email', 'normal'),
(False, None, 'send-sms-tasks', 'sms', 'team'),
(False, None, 'research-mode-tasks', 'sms', 'test'),
(True, 'notify-internal-tasks', 'research-mode-tasks', 'email', 'normal'),
(False, 'notify-internal-tasks', 'notify-internal-tasks', 'sms', 'normal'),
(False, 'notify-internal-tasks', 'notify-internal-tasks', 'email', 'normal'),
(False, 'notify-internal-tasks', 'research-mode-tasks', 'sms', 'test')])
def test_send_notification_to_queue(notify_db, notify_db_session,
research_mode, requested_queue, expected_queue,
notification_type, key_type, mocker):
mocked = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type))
@pytest.mark.parametrize((
'research_mode, requested_queue, notification_type, key_type, expected_queue, expected_task'
), [
(True, None, 'sms', 'normal', 'research-mode-tasks', 'provider_tasks.deliver_sms'),
(True, None, 'email', 'normal', 'research-mode-tasks', 'provider_tasks.deliver_email'),
(True, None, 'email', 'team', 'research-mode-tasks', 'provider_tasks.deliver_email'),
(True, None, 'letter', 'normal', 'research-mode-tasks', 'letters_pdf_tasks.create_letters_pdf'),
(False, None, 'sms', 'normal', 'send-sms-tasks', 'provider_tasks.deliver_sms'),
(False, None, 'email', 'normal', 'send-email-tasks', 'provider_tasks.deliver_email'),
(False, None, 'sms', 'team', 'send-sms-tasks', 'provider_tasks.deliver_sms'),
(False, None, 'letter', 'normal', 'create-letters-pdf-tasks', 'letters_pdf_tasks.create_letters_pdf'),
(False, None, 'sms', 'test', 'research-mode-tasks', 'provider_tasks.deliver_sms'),
(True, 'notify-internal-tasks', 'email', 'normal', 'research-mode-tasks', 'provider_tasks.deliver_email'),
(False, 'notify-internal-tasks', 'sms', 'normal', 'notify-internal-tasks', 'provider_tasks.deliver_sms'),
(False, 'notify-internal-tasks', 'email', 'normal', 'notify-internal-tasks', 'provider_tasks.deliver_email'),
(False, 'notify-internal-tasks', 'sms', 'test', 'research-mode-tasks', 'provider_tasks.deliver_sms'),
])
def test_send_notification_to_queue(
notify_db,
notify_db_session,
research_mode,
requested_queue,
notification_type,
key_type,
expected_queue,
expected_task,
mocker,
):
mocked = mocker.patch('app.celery.{}.apply_async'.format(expected_task))
Notification = namedtuple('Notification', ['id', 'key_type', 'notification_type', 'created_at'])
notification = Notification(
id=uuid.uuid4(),

View File

@@ -258,6 +258,22 @@ def test_send_one_off_letter_notification_should_use_template_reply_to_text(samp
assert notification.reply_to_text == "Edinburgh, ED1 1AA"
def test_send_one_off_letter_should_not_make_pdf_in_research_mode(sample_letter_template):
sample_letter_template.service.research_mode = True
data = {
'to': 'A. Name',
'template_id': str(sample_letter_template.id),
'created_by': str(sample_letter_template.service.created_by_id)
}
notification = send_one_off_notification(service_id=sample_letter_template.service.id, post_data=data)
notification = Notification.query.get(notification['id'])
assert notification.status == "delivered"
def test_send_one_off_sms_notification_should_use_sms_sender_reply_to_text(sample_service, celery_mock):
template = create_template(service=sample_service, template_type=SMS_TYPE)
sms_sender = create_service_sms_sender(