2017-06-16 13:47:00 +01:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2017-01-19 14:55:22 +00:00
|
|
|
|
import uuid
|
2016-06-24 10:15:20 +01:00
|
|
|
|
from functools import partial
|
2018-02-20 11:22:17 +00:00
|
|
|
|
from glob import glob
|
|
|
|
|
|
from io import BytesIO
|
|
|
|
|
|
from itertools import repeat
|
|
|
|
|
|
from os import path
|
2021-12-07 12:39:37 +00:00
|
|
|
|
from random import randbytes
|
2018-09-26 16:41:04 +01:00
|
|
|
|
from uuid import uuid4
|
2018-02-28 14:45:57 +00:00
|
|
|
|
from zipfile import BadZipFile
|
2016-11-02 16:53:40 +00:00
|
|
|
|
|
|
|
|
|
|
import pytest
|
2016-01-14 16:00:13 +00:00
|
|
|
|
from flask import url_for
|
2017-06-29 15:31:44 +01:00
|
|
|
|
from notifications_python_client.errors import HTTPError
|
2017-04-26 16:19:49 +01:00
|
|
|
|
from notifications_utils.recipients import RecipientCSV
|
2022-12-05 15:33:44 -05:00
|
|
|
|
from notifications_utils.template import SMSPreviewTemplate
|
2018-04-25 14:12:58 +01:00
|
|
|
|
from xlrd.biffh import XLRDError
|
|
|
|
|
|
from xlrd.xldate import (
|
|
|
|
|
|
XLDateAmbiguous,
|
|
|
|
|
|
XLDateError,
|
|
|
|
|
|
XLDateNegative,
|
|
|
|
|
|
XLDateTooLarge,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2018-02-20 11:22:17 +00:00
|
|
|
|
from tests import (
|
|
|
|
|
|
validate_route_permission,
|
|
|
|
|
|
validate_route_permission_with_client,
|
|
|
|
|
|
)
|
2017-04-07 09:18:00 +01:00
|
|
|
|
from tests.conftest import (
|
2018-02-20 11:22:17 +00:00
|
|
|
|
SERVICE_ONE_ID,
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user,
|
|
|
|
|
|
create_active_user_with_permissions,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
create_multiple_email_reply_to_addresses,
|
|
|
|
|
|
create_multiple_sms_senders,
|
|
|
|
|
|
create_template,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
mock_get_service_email_template,
|
2017-04-07 09:18:00 +01:00
|
|
|
|
mock_get_service_template,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
normalize_spaces,
|
2017-04-07 09:18:00 +01:00
|
|
|
|
)
|
2015-12-17 16:21:34 +00:00
|
|
|
|
|
2016-02-22 17:17:18 +00:00
|
|
|
|
template_types = ['email', 'sms']
|
2015-12-17 16:21:34 +00:00
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
|
unchanging_fake_uuid = uuid.uuid4()
|
|
|
|
|
|
|
2016-05-05 15:41:11 +01:00
|
|
|
|
# The * ignores hidden files, eg .DS_Store
|
|
|
|
|
|
test_spreadsheet_files = glob(path.join('tests', 'spreadsheet_files', '*'))
|
2016-05-13 21:25:59 +01:00
|
|
|
|
test_non_spreadsheet_files = glob(path.join('tests', 'non_spreadsheet_files', '*'))
|
2016-05-05 15:41:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
2020-01-08 09:10:04 +00:00
|
|
|
|
def test_show_correct_title_and_description_for_email_sender_type(
|
2017-10-16 16:35:35 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
multiple_reply_to_email_addresses,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.set_sender',
|
2020-01-08 09:10:04 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert page.select_one('.govuk-fieldset__legend h1').text.strip() == 'Where should replies come back to?'
|
2017-10-16 16:35:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
2020-01-08 09:10:04 +00:00
|
|
|
|
def test_show_correct_title_and_description_for_sms_sender_type(
|
2017-10-16 16:35:35 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
multiple_sms_senders,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.set_sender',
|
2020-01-08 09:10:04 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert page.select_one('.govuk-fieldset__legend h1').text.strip() == 'Who should the message come from?'
|
2020-01-08 09:10:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_default_email_sender_is_checked_and_has_hint(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
multiple_reply_to_email_addresses,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert page.select('.govuk-radios input')[0].has_attr('checked')
|
2023-06-08 13:12:00 -04:00
|
|
|
|
assert normalize_spaces(page.select_one('.govuk-radios .usa-hint').text) == "(Default)"
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert not page.select('.govuk-radios input')[1].has_attr('checked')
|
2020-01-08 09:10:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_default_sms_sender_is_checked_and_has_hint(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
multiple_sms_senders_with_diff_default,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert page.select('.govuk-radios input')[0].has_attr('checked')
|
2023-06-08 13:12:00 -04:00
|
|
|
|
assert normalize_spaces(page.select_one('.govuk-radios .usa-hint').text) == "(Default)"
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert not page.select('.govuk-radios input')[1].has_attr('checked')
|
2020-01-08 09:10:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_default_sms_sender_is_checked_and_has_hint_when_there_are_no_inbound_numbers(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
multiple_sms_senders_no_inbound,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert page.select('.govuk-radios input')[0].has_attr('checked')
|
2023-06-08 13:12:00 -04:00
|
|
|
|
assert normalize_spaces(page.select_one('.govuk-radios .usa-hint').text) == "(Default)"
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert not page.select('.govuk-radios input')[1].has_attr('checked')
|
2017-11-02 15:48:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_default_inbound_sender_is_checked_and_has_hint_with_default_and_receives_text(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
multiple_sms_senders
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert page.select('.govuk-radios input')[0].has_attr('checked')
|
2017-11-02 15:48:19 +00:00
|
|
|
|
assert normalize_spaces(
|
2023-06-08 13:12:00 -04:00
|
|
|
|
page.select_one('.govuk-radios .usa-hint').text) == "(Default and receives replies)"
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert not page.select('.govuk-radios input')[1].has_attr('checked')
|
|
|
|
|
|
assert not page.select('.govuk-radios input')[2].has_attr('checked')
|
2017-10-16 16:35:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-11-02 16:30:49 +00:00
|
|
|
|
def test_sms_sender_has_receives_replies_hint(
|
2017-11-02 14:58:14 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
multiple_sms_senders
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert page.select('.govuk-radios input')[0].has_attr('checked')
|
2017-11-02 15:48:19 +00:00
|
|
|
|
assert normalize_spaces(
|
2023-06-08 13:12:00 -04:00
|
|
|
|
page.select_one('.govuk-radios .usa-hint').text) == "(Default and receives replies)"
|
2021-01-13 10:31:07 +00:00
|
|
|
|
assert not page.select('.govuk-radios input')[1].has_attr('checked')
|
|
|
|
|
|
assert not page.select('.govuk-radios input')[2].has_attr('checked')
|
2017-11-02 14:58:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-01-08 09:10:04 +00:00
|
|
|
|
@pytest.mark.parametrize('template_type, sender_data', [
|
2017-11-02 12:07:46 +00:00
|
|
|
|
(
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'email',
|
|
|
|
|
|
create_multiple_email_reply_to_addresses(),
|
2017-11-02 12:07:46 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'sms',
|
|
|
|
|
|
create_multiple_sms_senders()
|
2017-11-02 12:07:46 +00:00
|
|
|
|
)
|
|
|
|
|
|
])
|
2017-10-16 16:35:35 +01:00
|
|
|
|
def test_sender_session_is_present_after_selected(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
template_type,
|
2017-11-02 12:07:46 +00:00
|
|
|
|
sender_data,
|
|
|
|
|
|
mocker
|
2017-10-16 16:35:35 +01:00
|
|
|
|
):
|
2020-01-08 09:10:04 +00:00
|
|
|
|
template_data = create_template(template_type=template_type)
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value={'data': template_data})
|
|
|
|
|
|
|
|
|
|
|
|
if template_type == 'email':
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_reply_to_email_addresses', return_value=sender_data)
|
|
|
|
|
|
else:
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_sms_senders', return_value=sender_data)
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'sender': '1234'},
|
2017-10-16 16:35:35 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2017-10-16 16:35:35 +01:00
|
|
|
|
assert session['sender_id'] == '1234'
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-06 15:29:21 +00:00
|
|
|
|
def test_set_sender_redirects_if_no_reply_to_email_addresses(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
fake_uuid,
|
2020-01-06 15:29:21 +00:00
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
no_reply_to_email_addresses,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.get(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_url=url_for(
|
|
|
|
|
|
'.send_one_off',
|
2020-01-06 15:29:21 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_sender_redirects_if_no_sms_senders(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
no_sms_senders,
|
|
|
|
|
|
):
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_url=url_for(
|
|
|
|
|
|
'.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
2017-10-16 16:35:35 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-08 17:23:47 +00:00
|
|
|
|
def test_set_sender_redirects_if_one_email_sender(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
single_reply_to_email_address,
|
|
|
|
|
|
):
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_url=url_for(
|
|
|
|
|
|
'.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
assert session['sender_id'] == '1234'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_sender_redirects_if_one_sms_sender(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
single_sms_sender,
|
|
|
|
|
|
):
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_url=url_for(
|
|
|
|
|
|
'.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
assert session['sender_id'] == '1234'
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-05 15:41:11 +01:00
|
|
|
|
def test_that_test_files_exist():
|
|
|
|
|
|
assert len(test_spreadsheet_files) == 8
|
2016-05-13 21:25:59 +01:00
|
|
|
|
assert len(test_non_spreadsheet_files) == 6
|
2016-05-05 15:41:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-06-30 10:55:59 +01:00
|
|
|
|
def test_should_not_allow_files_to_be_uploaded_without_the_correct_permission(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
template_id = fake_uuid
|
|
|
|
|
|
service_one['permissions'] = []
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2017-06-30 10:55:59 +01:00
|
|
|
|
'.send_messages',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=template_id,
|
|
|
|
|
|
_follow_redirects=True,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
_expected_status=403,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2017-06-30 10:55:59 +01:00
|
|
|
|
|
2017-07-10 12:25:01 +01:00
|
|
|
|
assert page.select('main p')[0].text.strip() == "Sending text messages has been disabled for your service."
|
2023-06-08 13:12:00 -04:00
|
|
|
|
assert page.select(".usa-back-link")[0].text == "Back"
|
|
|
|
|
|
assert page.select(".usa-back-link")[0]['href'] == url_for(
|
2017-06-30 10:55:59 +01:00
|
|
|
|
'.view_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=template_id,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-08 12:49:29 +01:00
|
|
|
|
def test_example_spreadsheet(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_placeholders_same_as_recipient,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.send_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select_one('tbody tr').text
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'1 phone number name date'
|
|
|
|
|
|
)
|
2020-12-16 11:05:19 +00:00
|
|
|
|
assert page.select_one('input[type=file]').has_attr('accept')
|
2020-12-17 10:47:52 +00:00
|
|
|
|
assert page.select_one('input[type=file]')['accept'] == '.csv,.xlsx,.xls,.ods,.xlsm,.tsv'
|
2018-06-08 12:49:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-05-13 21:25:59 +01:00
|
|
|
|
@pytest.mark.parametrize(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
"filename, acceptable_file, expected_status",
|
2023-01-06 11:47:57 -05:00
|
|
|
|
list(zip(test_spreadsheet_files, repeat(True), repeat(302))) +
|
2021-12-31 12:08:14 +00:00
|
|
|
|
list(zip(test_non_spreadsheet_files, repeat(False), repeat(200)))
|
2016-05-13 21:25:59 +01:00
|
|
|
|
)
|
2016-05-05 15:41:11 +01:00
|
|
|
|
def test_upload_files_in_different_formats(
|
|
|
|
|
|
filename,
|
2016-05-13 21:25:59 +01:00
|
|
|
|
acceptable_file,
|
2021-12-31 12:08:14 +00:00
|
|
|
|
expected_status,
|
|
|
|
|
|
client_request,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
service_one,
|
2016-05-05 15:41:11 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_template,
|
2020-10-23 16:10:03 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2016-05-05 15:41:11 +01:00
|
|
|
|
mock_s3_upload,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
fake_uuid,
|
2016-05-05 15:41:11 +01:00
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
with open(filename, 'rb') as uploaded:
|
2021-12-31 12:08:14 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO(uploaded.read()), filename)},
|
|
|
|
|
|
_content_type='multipart/form-data',
|
|
|
|
|
|
_expected_status=expected_status,
|
2016-05-05 15:41:11 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2016-05-13 21:25:59 +01:00
|
|
|
|
if acceptable_file:
|
2016-05-15 07:47:50 +01:00
|
|
|
|
assert mock_s3_upload.call_args[0][1]['data'].strip() == (
|
2016-05-13 21:25:59 +01:00
|
|
|
|
"phone number,name,favourite colour,fruit\r\n"
|
2022-12-22 22:11:07 -05:00
|
|
|
|
"202 946 8050,Pete,Coral,tomato\r\n"
|
|
|
|
|
|
"202 712 5974,Not Pete,Magenta,Avacado\r\n"
|
|
|
|
|
|
"202 205 8823,Still Not Pete,Crimson,Pear"
|
2016-05-13 21:25:59 +01:00
|
|
|
|
)
|
2020-10-23 16:10:03 +01:00
|
|
|
|
mock_s3_set_metadata.assert_called_once_with(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
original_file_name=filename
|
|
|
|
|
|
)
|
2016-05-13 21:25:59 +01:00
|
|
|
|
else:
|
|
|
|
|
|
assert not mock_s3_upload.called
|
2018-02-28 14:45:57 +00:00
|
|
|
|
assert normalize_spaces(page.select_one('.banner-dangerous').text) == (
|
2019-09-13 12:06:44 +01:00
|
|
|
|
'Could not read {}. Try using a different file format.'.format(filename)
|
2018-02-28 14:45:57 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-23 16:10:03 +01:00
|
|
|
|
def test_send_messages_sanitises_and_truncates_file_name_for_metadata(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2020-10-23 16:10:03 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_s3_set_metadata,
|
|
|
|
|
|
mock_s3_get_metadata,
|
|
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_s3_download,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
filename = f"😁{'a' * 2000}.csv"
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO(''.encode('utf-8')), filename)},
|
|
|
|
|
|
_content_type='multipart/form-data',
|
|
|
|
|
|
_follow_redirects=False,
|
2020-10-23 16:10:03 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert len(
|
|
|
|
|
|
mock_s3_set_metadata.call_args_list[0][1]['original_file_name']
|
|
|
|
|
|
) < len(filename)
|
|
|
|
|
|
|
|
|
|
|
|
assert mock_s3_set_metadata.call_args_list[0][1]['original_file_name'].startswith('?')
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-28 14:45:57 +00:00
|
|
|
|
@pytest.mark.parametrize('exception, expected_error_message', [
|
|
|
|
|
|
(partial(UnicodeDecodeError, 'codec', b'', 1, 2, 'reason'), (
|
2019-09-13 12:06:44 +01:00
|
|
|
|
'Could not read example.xlsx. Try using a different file format.'
|
2018-02-28 14:45:57 +00:00
|
|
|
|
)),
|
|
|
|
|
|
(BadZipFile, (
|
2019-09-13 12:06:44 +01:00
|
|
|
|
'Could not read example.xlsx. Try using a different file format.'
|
2018-02-28 14:45:57 +00:00
|
|
|
|
)),
|
|
|
|
|
|
(XLRDError, (
|
2019-09-13 12:06:44 +01:00
|
|
|
|
'Could not read example.xlsx. Try using a different file format.'
|
2018-02-28 14:45:57 +00:00
|
|
|
|
)),
|
|
|
|
|
|
(XLDateError, (
|
2019-09-13 09:35:05 +01:00
|
|
|
|
'example.xlsx contains numbers or dates that Notify cannot understand. '
|
2018-02-28 14:45:57 +00:00
|
|
|
|
'Try formatting all columns as ‘text’ or export your file as CSV.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
(XLDateNegative, (
|
2019-09-13 09:35:05 +01:00
|
|
|
|
'example.xlsx contains numbers or dates that Notify cannot understand. '
|
2018-02-28 14:45:57 +00:00
|
|
|
|
'Try formatting all columns as ‘text’ or export your file as CSV.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
(XLDateAmbiguous, (
|
2019-09-13 09:35:05 +01:00
|
|
|
|
'example.xlsx contains numbers or dates that Notify cannot understand. '
|
2018-02-28 14:45:57 +00:00
|
|
|
|
'Try formatting all columns as ‘text’ or export your file as CSV.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
(XLDateTooLarge, (
|
2019-09-13 09:35:05 +01:00
|
|
|
|
'example.xlsx contains numbers or dates that Notify cannot understand. '
|
2018-02-28 14:45:57 +00:00
|
|
|
|
'Try formatting all columns as ‘text’ or export your file as CSV.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_shows_error_if_parsing_exception(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2018-02-28 14:45:57 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
exception,
|
|
|
|
|
|
expected_error_message,
|
2019-11-04 11:07:55 +00:00
|
|
|
|
fake_uuid,
|
2018-02-28 14:45:57 +00:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
def _raise_exception_or_partial_exception(file_content, filename):
|
|
|
|
|
|
raise exception()
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.Spreadsheet.from_file',
|
|
|
|
|
|
side_effect=_raise_exception_or_partial_exception
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO(b'example'), 'example.xlsx')},
|
|
|
|
|
|
_content_type='multipart/form-data',
|
|
|
|
|
|
_expected_status=200,
|
2018-02-28 14:45:57 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.banner-dangerous').text) == (
|
|
|
|
|
|
expected_error_message
|
|
|
|
|
|
)
|
2016-05-05 15:41:11 +01:00
|
|
|
|
|
2016-02-22 17:17:18 +00:00
|
|
|
|
|
2019-05-28 17:44:27 +01:00
|
|
|
|
def test_upload_csv_file_with_errors_shows_check_page_with_errors(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
service_one,
|
2016-02-26 10:54:06 +00:00
|
|
|
|
mocker,
|
2016-05-17 09:23:33 +01:00
|
|
|
|
mock_get_service_template_with_placeholders,
|
2020-10-23 16:10:03 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2016-02-29 17:03:56 +00:00
|
|
|
|
mock_s3_upload,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
fake_uuid,
|
2016-02-22 17:17:18 +00:00
|
|
|
|
):
|
2016-01-13 22:34:36 +00:00
|
|
|
|
|
2016-05-17 09:23:33 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
|
|
|
|
|
return_value="""
|
|
|
|
|
|
phone number,name
|
2022-12-22 22:11:07 -05:00
|
|
|
|
+12028675109
|
|
|
|
|
|
+12028675109
|
2016-05-17 09:23:33 +01:00
|
|
|
|
"""
|
|
|
|
|
|
)
|
2015-12-17 16:21:34 +00:00
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO(''.encode('utf-8')), 'example.csv')},
|
|
|
|
|
|
_content_type='multipart/form-data',
|
|
|
|
|
|
_follow_redirects=True,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
)
|
2018-03-13 16:29:20 +00:00
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-04-30 12:10:54 +01:00
|
|
|
|
assert 'file_uploads' not in session
|
2018-03-13 16:29:20 +00:00
|
|
|
|
|
2020-12-16 11:05:19 +00:00
|
|
|
|
assert page.select_one('input[type=file]').has_attr('accept')
|
2020-12-17 10:47:52 +00:00
|
|
|
|
assert page.select_one('input[type=file]')['accept'] == '.csv,.xlsx,.xls,.ods,.xlsm,.tsv'
|
2020-12-16 11:05:19 +00:00
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
assert 'There’s a problem with example.csv' in page.text
|
2022-12-22 22:11:07 -05:00
|
|
|
|
assert '+12028675109' in page.text
|
2021-12-31 12:08:14 +00:00
|
|
|
|
assert 'Missing' in page.text
|
|
|
|
|
|
assert 'Upload your file again' in page.text
|
2016-02-26 10:54:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-11-21 12:12:04 +00:00
|
|
|
|
def test_upload_csv_file_with_empty_message_shows_check_page_with_errors(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2019-11-21 12:12:04 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_empty_service_template_with_optional_placeholder,
|
2020-10-23 16:10:03 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2019-11-21 12:12:04 +00:00
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
|
|
|
|
|
return_value="""
|
|
|
|
|
|
phone number, show_placeholder
|
2022-12-22 22:11:07 -05:00
|
|
|
|
+12028675109, yes
|
|
|
|
|
|
+12028675109, no
|
2019-11-21 12:12:04 +00:00
|
|
|
|
"""
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO(''.encode('utf-8')), 'example.csv')},
|
|
|
|
|
|
_content_type='multipart/form-data',
|
|
|
|
|
|
_follow_redirects=True,
|
2019-11-21 12:12:04 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2019-11-21 12:12:04 +00:00
|
|
|
|
assert 'file_uploads' not in session
|
|
|
|
|
|
|
2020-04-11 11:06:58 +01:00
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select_one('.banner-dangerous').text
|
|
|
|
|
|
) == (
|
2020-10-21 13:07:59 +01:00
|
|
|
|
'There’s a problem with example.csv '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'You need to check you have content for the empty message in 1 row.'
|
2020-04-11 11:06:58 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
normalize_spaces(row.text) for row in page.select('tbody tr')
|
|
|
|
|
|
] == [
|
2020-04-11 11:42:13 +01:00
|
|
|
|
'3 No content for this message',
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'+12028675109 no',
|
2020-04-11 11:06:58 +01:00
|
|
|
|
]
|
2020-04-11 11:42:13 +01:00
|
|
|
|
assert normalize_spaces(page.select_one('.table-field-index').text) == '3'
|
|
|
|
|
|
assert page.select_one('.table-field-index')['rowspan'] == '2'
|
|
|
|
|
|
assert normalize_spaces(page.select('tbody tr td')[0].text) == '3'
|
|
|
|
|
|
assert normalize_spaces(page.select('tbody tr td')[1].text) == (
|
|
|
|
|
|
'No content for this message'
|
|
|
|
|
|
)
|
|
|
|
|
|
assert page.select('tbody tr td')[1]['colspan'] == '2'
|
2019-11-21 12:12:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-04-20 12:35:59 +01:00
|
|
|
|
def test_upload_csv_file_with_very_long_placeholder_shows_check_page_with_errors(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2020-04-20 12:35:59 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
2020-10-23 16:10:03 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2020-04-20 12:35:59 +01:00
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2020-04-27 10:27:43 +01:00
|
|
|
|
big_placeholder = ' '.join(['not ok'] * 402)
|
2020-04-20 12:35:59 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
|
|
|
|
|
return_value=f"""
|
|
|
|
|
|
phone number, name
|
2022-12-22 22:11:07 -05:00
|
|
|
|
+12028675109, {big_placeholder}
|
|
|
|
|
|
+12027700900, {big_placeholder}
|
2020-04-20 12:35:59 +01:00
|
|
|
|
"""
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO(''.encode('utf-8')), 'example.csv')},
|
|
|
|
|
|
_content_type='multipart/form-data',
|
|
|
|
|
|
_follow_redirects=True
|
2020-04-20 12:35:59 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2020-04-20 12:35:59 +01:00
|
|
|
|
assert 'file_uploads' not in session
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select_one('.banner-dangerous').text
|
|
|
|
|
|
) == (
|
2020-10-21 13:07:59 +01:00
|
|
|
|
'There’s a problem with example.csv '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'You need to shorten the messages in 2 rows.'
|
2020-04-20 12:35:59 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
normalize_spaces(row.text) for row in page.select('tbody tr')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
'2 Message is too long',
|
2022-12-22 22:11:07 -05:00
|
|
|
|
f'+12028675109 {big_placeholder}',
|
2020-04-20 12:35:59 +01:00
|
|
|
|
'3 Message is too long',
|
2022-12-22 22:11:07 -05:00
|
|
|
|
f'+12027700900 {big_placeholder}',
|
2020-04-20 12:35:59 +01:00
|
|
|
|
]
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.table-field-index').text) == '2'
|
|
|
|
|
|
assert page.select_one('.table-field-index')['rowspan'] == '2'
|
|
|
|
|
|
assert normalize_spaces(page.select('tbody tr td')[0].text) == '2'
|
|
|
|
|
|
assert normalize_spaces(page.select('tbody tr td')[1].text) == (
|
|
|
|
|
|
'Message is too long'
|
|
|
|
|
|
)
|
|
|
|
|
|
assert page.select('tbody tr td')[1]['colspan'] == '2'
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-27 12:06:16 +00:00
|
|
|
|
@pytest.mark.parametrize('file_contents, expected_error,', [
|
|
|
|
|
|
(
|
|
|
|
|
|
"""
|
|
|
|
|
|
telephone,name
|
2022-12-22 22:11:07 -05:00
|
|
|
|
+12028675109
|
2017-02-27 12:06:16 +00:00
|
|
|
|
""",
|
|
|
|
|
|
(
|
2019-10-03 14:24:28 +01:00
|
|
|
|
'There’s a problem with your column names '
|
|
|
|
|
|
'Your file needs a column called ‘phone number’. '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'Right now it has columns called ‘telephone’ and ‘name’.'
|
2017-02-27 12:06:16 +00:00
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"""
|
|
|
|
|
|
phone number
|
2022-12-22 22:11:07 -05:00
|
|
|
|
+12028675109
|
2017-02-27 12:06:16 +00:00
|
|
|
|
""",
|
|
|
|
|
|
(
|
2019-10-03 14:24:28 +01:00
|
|
|
|
'Your column names need to match the double brackets in your template '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'Your file is missing a column called ‘name’.'
|
2017-02-27 12:06:16 +00:00
|
|
|
|
)
|
2017-02-27 14:46:01 +00:00
|
|
|
|
),
|
2018-03-02 10:45:29 +00:00
|
|
|
|
(
|
|
|
|
|
|
"""
|
|
|
|
|
|
phone number, phone number, PHONE_NUMBER
|
2022-12-22 22:11:07 -05:00
|
|
|
|
+12027900111,+12027900222,+12027900333,
|
2018-03-02 10:45:29 +00:00
|
|
|
|
""",
|
|
|
|
|
|
(
|
2019-10-03 14:24:28 +01:00
|
|
|
|
'There’s a problem with your column names '
|
|
|
|
|
|
'We found more than one column called ‘phone number’ or ‘PHONE_NUMBER’. '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'Delete or rename one of these columns and try again.'
|
2018-03-02 10:45:29 +00:00
|
|
|
|
)
|
|
|
|
|
|
),
|
2017-12-20 11:59:51 +00:00
|
|
|
|
(
|
|
|
|
|
|
"""
|
|
|
|
|
|
phone number, name
|
|
|
|
|
|
""",
|
|
|
|
|
|
(
|
|
|
|
|
|
'Your file is missing some rows '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'It needs at least one row of data.'
|
2017-12-20 11:59:51 +00:00
|
|
|
|
)
|
|
|
|
|
|
),
|
2017-02-27 14:46:01 +00:00
|
|
|
|
(
|
2022-12-22 22:11:07 -05:00
|
|
|
|
"+12028675109",
|
2017-02-27 14:46:01 +00:00
|
|
|
|
(
|
|
|
|
|
|
'Your file is missing some rows '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'It needs at least one row of data, and columns called ‘name’ and ‘phone number’.'
|
2017-02-27 14:46:01 +00:00
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"",
|
|
|
|
|
|
(
|
|
|
|
|
|
'Your file is missing some rows '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'It needs at least one row of data, and columns called ‘name’ and ‘phone number’.'
|
2017-02-27 14:46:01 +00:00
|
|
|
|
)
|
|
|
|
|
|
),
|
2017-07-20 15:49:12 +01:00
|
|
|
|
(
|
|
|
|
|
|
"""
|
|
|
|
|
|
phone number, name
|
2022-12-22 22:11:07 -05:00
|
|
|
|
+12028675109, example
|
2017-07-20 15:49:12 +01:00
|
|
|
|
, example
|
2022-12-22 22:11:07 -05:00
|
|
|
|
+12028675109, example
|
2017-07-20 15:49:12 +01:00
|
|
|
|
""",
|
|
|
|
|
|
(
|
2020-10-21 13:07:59 +01:00
|
|
|
|
'There’s a problem with example.csv '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'You need to enter missing data in 1 row.'
|
2017-07-20 15:49:12 +01:00
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"""
|
|
|
|
|
|
phone number, name
|
2022-12-22 22:11:07 -05:00
|
|
|
|
+12028675109, example
|
|
|
|
|
|
+12028675109,
|
|
|
|
|
|
+12028675109, example
|
2017-07-20 15:49:12 +01:00
|
|
|
|
""",
|
|
|
|
|
|
(
|
2020-10-21 13:07:59 +01:00
|
|
|
|
'There’s a problem with example.csv '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'You need to enter missing data in 1 row.'
|
2017-07-20 15:49:12 +01:00
|
|
|
|
)
|
|
|
|
|
|
),
|
2017-02-27 12:06:16 +00:00
|
|
|
|
])
|
2019-05-28 17:44:27 +01:00
|
|
|
|
def test_upload_csv_file_with_missing_columns_shows_error(
|
2018-03-29 11:56:53 +01:00
|
|
|
|
client_request,
|
2017-02-16 11:07:26 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
2020-10-23 16:10:03 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2017-02-16 11:07:26 +00:00
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2017-02-17 09:57:58 +00:00
|
|
|
|
service_one,
|
2017-02-16 11:07:26 +00:00
|
|
|
|
fake_uuid,
|
2017-02-27 12:06:16 +00:00
|
|
|
|
file_contents,
|
|
|
|
|
|
expected_error,
|
2017-02-16 11:07:26 +00:00
|
|
|
|
):
|
|
|
|
|
|
|
2017-02-27 12:06:16 +00:00
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value=file_contents)
|
2017-02-16 11:07:26 +00:00
|
|
|
|
|
2018-03-29 11:56:53 +01:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_messages', service_id=service_one['id'], template_id=fake_uuid,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
_data={'file': (BytesIO(''.encode('utf-8')), 'example.csv')},
|
2018-03-29 11:56:53 +01:00
|
|
|
|
_follow_redirects=True,
|
2017-02-16 11:07:26 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2018-03-29 11:56:53 +01:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-04-30 12:10:54 +01:00
|
|
|
|
assert 'file_uploads' not in session
|
2018-03-29 11:56:53 +01:00
|
|
|
|
|
2020-12-16 11:05:19 +00:00
|
|
|
|
assert page.select_one('input[type=file]').has_attr('accept')
|
2020-12-17 10:47:52 +00:00
|
|
|
|
assert page.select_one('input[type=file]')['accept'] == '.csv,.xlsx,.xls,.ods,.xlsm,.tsv'
|
2018-03-29 11:56:53 +01:00
|
|
|
|
assert normalize_spaces(page.select('.banner-dangerous')[0].text) == expected_error
|
2017-02-16 11:07:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_upload_csv_invalid_extension(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_login,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
service_one,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2016-06-17 11:54:01 +01:00
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO('contents'.encode('utf-8')), 'invalid.txt')},
|
|
|
|
|
|
_content_type='multipart/form-data',
|
|
|
|
|
|
_follow_redirects=True,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
)
|
2016-04-29 15:40:35 +01:00
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
assert "invalid.txt is not a spreadsheet that Notify can read" in page.text
|
2016-04-29 15:40:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
2021-12-07 12:39:37 +00:00
|
|
|
|
def test_upload_csv_size_too_big(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2021-12-07 12:39:37 +00:00
|
|
|
|
mock_login,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO(randbytes(11_000_000)), 'invalid.csv')},
|
|
|
|
|
|
_content_type='multipart/form-data',
|
|
|
|
|
|
_follow_redirects=True,
|
2021-12-07 12:39:37 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
assert "File must be smaller than 10Mb" in page.text
|
2021-12-07 12:39:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-12-07 15:42:58 +00:00
|
|
|
|
def test_upload_valid_csv_redirects_to_check_page(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_s3_upload,
|
2020-10-23 16:10:03 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2017-12-07 15:42:58 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.send_messages', service_id=SERVICE_ONE_ID, template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO(''.encode('utf-8')), 'valid.csv')},
|
|
|
|
|
|
_expected_status=302,
|
2019-06-17 16:53:18 +01:00
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
),
|
2017-12-07 15:42:58 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-15 11:25:11 +00:00
|
|
|
|
@pytest.mark.parametrize('extra_args, expected_link_in_first_row, expected_recipient, expected_message', [
|
2017-12-06 22:04:58 +00:00
|
|
|
|
(
|
|
|
|
|
|
{},
|
2018-01-15 11:25:11 +00:00
|
|
|
|
None,
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'To: 2028675301',
|
2017-12-06 22:04:58 +00:00
|
|
|
|
'Test Service: A, Template <em>content</em> with & entity',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2018-01-15 11:35:45 +00:00
|
|
|
|
{'row_index': 2},
|
2018-01-15 11:25:11 +00:00
|
|
|
|
None,
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'To: 2028675301',
|
2017-12-06 22:04:58 +00:00
|
|
|
|
'Test Service: A, Template <em>content</em> with & entity',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2018-01-15 11:35:45 +00:00
|
|
|
|
{'row_index': 4},
|
2018-01-15 11:25:11 +00:00
|
|
|
|
True,
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'To: 2028675303',
|
2017-12-06 22:04:58 +00:00
|
|
|
|
'Test Service: C, Template <em>content</em> with & entity',
|
|
|
|
|
|
),
|
|
|
|
|
|
])
|
2017-12-07 15:42:58 +00:00
|
|
|
|
def test_upload_valid_csv_shows_preview_and_table(
|
2017-12-07 14:32:05 +00:00
|
|
|
|
client_request,
|
2017-04-04 09:46:57 +01:00
|
|
|
|
mocker,
|
2017-12-06 22:04:58 +00:00
|
|
|
|
mock_get_live_service,
|
2017-04-04 09:46:57 +01:00
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-04-27 16:05:04 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2017-04-04 09:46:57 +01:00
|
|
|
|
fake_uuid,
|
2017-12-06 22:04:58 +00:00
|
|
|
|
extra_args,
|
2018-01-15 11:25:11 +00:00
|
|
|
|
expected_link_in_first_row,
|
2017-12-06 22:04:58 +00:00
|
|
|
|
expected_recipient,
|
|
|
|
|
|
expected_message,
|
2017-04-04 09:46:57 +01:00
|
|
|
|
):
|
|
|
|
|
|
|
2017-12-07 15:42:58 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {'template_id': fake_uuid}
|
|
|
|
|
|
}
|
2017-12-07 15:42:58 +00:00
|
|
|
|
|
2017-04-04 09:46:57 +01:00
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value="""
|
|
|
|
|
|
phone number,name,thing,thing,thing
|
2022-12-22 22:11:07 -05:00
|
|
|
|
2028675301, A, foo, foo, foo
|
|
|
|
|
|
2028675302, B, foo, foo, foo
|
|
|
|
|
|
2028675303, C, foo, foo,
|
2017-04-04 09:46:57 +01:00
|
|
|
|
""")
|
|
|
|
|
|
|
2017-12-07 15:42:58 +00:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
2017-12-07 15:42:58 +00:00
|
|
|
|
upload_id=fake_uuid,
|
2017-12-06 22:04:58 +00:00
|
|
|
|
**extra_args
|
2017-04-04 09:46:57 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2018-04-27 16:05:04 +01:00
|
|
|
|
mock_s3_set_metadata.assert_called_once_with(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
notification_count=3,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
valid=True,
|
2018-04-30 10:06:33 +01:00
|
|
|
|
original_file_name='example.csv',
|
2018-04-27 16:05:04 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2017-05-25 08:31:58 +01:00
|
|
|
|
assert page.h1.text.strip() == 'Preview of Two week reminder'
|
2017-12-06 22:04:58 +00:00
|
|
|
|
assert page.select_one('.sms-message-recipient').text.strip() == expected_recipient
|
|
|
|
|
|
assert page.select_one('.sms-message-wrapper').text.strip() == expected_message
|
|
|
|
|
|
|
2018-01-15 11:25:11 +00:00
|
|
|
|
assert page.select_one('.table-field-index').text.strip() == '2'
|
|
|
|
|
|
|
|
|
|
|
|
if expected_link_in_first_row:
|
|
|
|
|
|
assert page.select_one('.table-field-index a')['href'] == url_for(
|
2018-05-21 10:30:09 +01:00
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
row_index=2,
|
|
|
|
|
|
original_file_name='example.csv',
|
2018-01-15 11:25:11 +00:00
|
|
|
|
)
|
|
|
|
|
|
else:
|
|
|
|
|
|
assert not page.select_one('.table-field-index').select_one('a')
|
|
|
|
|
|
|
2018-03-09 15:07:47 +00:00
|
|
|
|
for row_index, row in enumerate([
|
2017-04-04 09:46:57 +01:00
|
|
|
|
(
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'<td class="table-field-left-aligned"> <div class=""> 2028675301 </div> </td>',
|
2019-04-29 16:21:47 +01:00
|
|
|
|
'<td class="table-field-left-aligned"> <div class=""> A </div> </td>',
|
2018-03-09 15:07:47 +00:00
|
|
|
|
(
|
2019-04-29 16:21:47 +01:00
|
|
|
|
'<td class="table-field-left-aligned"> '
|
2018-03-09 15:07:47 +00:00
|
|
|
|
'<div class="table-field-status-default"> '
|
2019-04-23 11:26:36 +01:00
|
|
|
|
'<ul> '
|
2018-03-09 15:07:47 +00:00
|
|
|
|
'<li>foo</li> <li>foo</li> <li>foo</li> '
|
|
|
|
|
|
'</ul> '
|
|
|
|
|
|
'</div> '
|
|
|
|
|
|
'</td>'
|
|
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'<td class="table-field-left-aligned"> <div class=""> 2028675302 </div> </td>',
|
2019-04-29 16:21:47 +01:00
|
|
|
|
'<td class="table-field-left-aligned"> <div class=""> B </div> </td>',
|
2018-03-09 15:07:47 +00:00
|
|
|
|
(
|
2019-04-29 16:21:47 +01:00
|
|
|
|
'<td class="table-field-left-aligned"> '
|
2018-03-09 15:07:47 +00:00
|
|
|
|
'<div class="table-field-status-default"> '
|
2019-04-23 11:26:36 +01:00
|
|
|
|
'<ul> '
|
2018-03-09 15:07:47 +00:00
|
|
|
|
'<li>foo</li> <li>foo</li> <li>foo</li> '
|
|
|
|
|
|
'</ul> '
|
|
|
|
|
|
'</div> '
|
|
|
|
|
|
'</td>'
|
|
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'<td class="table-field-left-aligned"> <div class=""> 2028675303 </div> </td>',
|
2019-04-29 16:21:47 +01:00
|
|
|
|
'<td class="table-field-left-aligned"> <div class=""> C </div> </td>',
|
2018-03-09 15:07:47 +00:00
|
|
|
|
(
|
2019-04-29 16:21:47 +01:00
|
|
|
|
'<td class="table-field-left-aligned"> '
|
2018-03-09 15:07:47 +00:00
|
|
|
|
'<div class="table-field-status-default"> '
|
2019-04-23 11:26:36 +01:00
|
|
|
|
'<ul> '
|
2018-03-09 15:07:47 +00:00
|
|
|
|
'<li>foo</li> <li>foo</li> '
|
|
|
|
|
|
'</ul> '
|
|
|
|
|
|
'</div> '
|
|
|
|
|
|
'</td>'
|
|
|
|
|
|
)
|
2017-04-04 09:46:57 +01:00
|
|
|
|
),
|
|
|
|
|
|
]):
|
2018-03-09 15:07:47 +00:00
|
|
|
|
for index, cell in enumerate(row):
|
|
|
|
|
|
row = page.select('table tbody tr')[row_index]
|
2019-06-17 17:09:45 +01:00
|
|
|
|
assert 'id' not in row
|
2018-03-09 15:07:47 +00:00
|
|
|
|
assert normalize_spaces(str(row.select('td')[index + 1])) == cell
|
2022-12-05 16:35:46 -05:00
|
|
|
|
|
2018-05-10 17:00:20 +01:00
|
|
|
|
|
2018-03-02 10:45:29 +00:00
|
|
|
|
def test_show_all_columns_if_there_are_duplicate_recipient_columns(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2018-03-02 10:45:29 +00:00
|
|
|
|
fake_uuid,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-03-02 10:45:29 +00:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {'template_id': fake_uuid}
|
|
|
|
|
|
}
|
2018-03-02 10:45:29 +00:00
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value="""
|
|
|
|
|
|
phone number, phone_number, PHONENUMBER
|
2022-12-22 22:11:07 -05:00
|
|
|
|
2028675301, 2028675302, 2028675303
|
2018-03-02 10:45:29 +00:00
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
2018-03-02 10:45:29 +00:00
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('thead').text) == (
|
|
|
|
|
|
'Row in file1 phone number phone_number PHONENUMBER'
|
|
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('tbody').text) == (
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'2 2028675303 2028675303 2028675303'
|
2018-03-02 10:45:29 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-06 22:04:58 +00:00
|
|
|
|
@pytest.mark.parametrize('row_index, expected_status', [
|
2018-01-15 11:35:45 +00:00
|
|
|
|
(0, 404),
|
|
|
|
|
|
(1, 404),
|
2017-12-06 22:04:58 +00:00
|
|
|
|
(2, 200),
|
2018-01-15 11:35:45 +00:00
|
|
|
|
(3, 200),
|
|
|
|
|
|
(4, 200),
|
|
|
|
|
|
(5, 404),
|
2017-12-06 22:04:58 +00:00
|
|
|
|
])
|
|
|
|
|
|
def test_404_for_previewing_a_row_out_of_range(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-04-27 16:05:04 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2017-12-06 22:04:58 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
row_index,
|
|
|
|
|
|
expected_status,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {'template_id': fake_uuid}
|
|
|
|
|
|
}
|
2017-12-06 22:04:58 +00:00
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value="""
|
|
|
|
|
|
phone number,name,thing,thing,thing
|
2022-12-22 22:11:07 -05:00
|
|
|
|
2028675301, A, foo, foo, foo
|
|
|
|
|
|
2028675302, B, foo, foo, foo
|
|
|
|
|
|
2028675303, C, foo, foo, foo
|
2017-12-06 22:04:58 +00:00
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
2017-12-06 22:04:58 +00:00
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
row_index=row_index,
|
|
|
|
|
|
_expected_status=expected_status,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-12-05 15:33:44 -05:00
|
|
|
|
@pytest.mark.parametrize('template_type', ['sms', 'email'])
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_step_redirects_to_start_if_session_not_setup(
|
2017-05-25 09:18:26 +01:00
|
|
|
|
mocker,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2017-05-25 09:18:26 +01:00
|
|
|
|
mock_get_users_by_service,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
fake_uuid,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
template_type,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
):
|
2020-10-07 14:51:18 +01:00
|
|
|
|
template_data = create_template(template_type=template_type, content='Hi ((name))')
|
2020-01-08 09:10:04 +00:00
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value={'data': template_data})
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2017-06-26 14:56:14 +01:00
|
|
|
|
assert 'recipient' not in session
|
|
|
|
|
|
assert 'placeholders' not in session
|
2017-05-22 11:49:15 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=0,
|
2020-10-07 14:51:18 +01:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
2017-05-22 11:49:15 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-30 10:55:59 +01:00
|
|
|
|
def test_send_one_off_does_not_send_without_the_correct_permissions(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
template_id = fake_uuid
|
|
|
|
|
|
service_one['permissions'] = []
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2017-06-30 10:55:59 +01:00
|
|
|
|
'.send_one_off',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=template_id,
|
|
|
|
|
|
_follow_redirects=True,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
_expected_status=403,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2017-06-30 10:55:59 +01:00
|
|
|
|
|
2017-07-10 12:25:01 +01:00
|
|
|
|
assert page.select('main p')[0].text.strip() == "Sending text messages has been disabled for your service."
|
2023-06-08 13:12:00 -04:00
|
|
|
|
assert page.select(".usa-back-link")[0].text == "Back"
|
|
|
|
|
|
assert page.select(".usa-back-link")[0]['href'] == url_for(
|
2017-06-30 10:55:59 +01:00
|
|
|
|
'.view_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=template_id,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
|
@pytest.mark.parametrize('user', (
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
create_active_caseworking_user(),
|
2018-06-12 16:17:20 +01:00
|
|
|
|
))
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_has_correct_page_title(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2017-05-25 13:31:23 +01:00
|
|
|
|
service_one,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2017-05-25 13:31:23 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
user,
|
2017-05-25 13:31:23 +01:00
|
|
|
|
):
|
2023-01-19 17:29:21 -05:00
|
|
|
|
client_request.login(user)
|
2020-10-07 14:51:18 +01:00
|
|
|
|
template_data = create_template(template_type='sms', name='Two week reminder', content='Hi there ((name))')
|
2020-01-08 09:10:04 +00:00
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value={'data': template_data})
|
2017-05-25 13:31:23 +01:00
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.send_one_off',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=0,
|
|
|
|
|
|
_follow_redirects=True,
|
2017-05-25 13:31:23 +01:00
|
|
|
|
)
|
2020-10-07 14:51:18 +01:00
|
|
|
|
assert page.h1.text.strip() == "Send ‘Two week reminder’"
|
2017-05-25 13:31:23 +01:00
|
|
|
|
|
2020-10-05 11:55:15 +01:00
|
|
|
|
assert len(page.select('.banner-tour')) == 0
|
2017-06-01 13:29:30 +01:00
|
|
|
|
|
2017-05-25 13:31:23 +01:00
|
|
|
|
|
2020-10-07 14:51:18 +01:00
|
|
|
|
@pytest.mark.parametrize('step_index, prefilled, expected_field_label', [
|
2019-05-03 13:07:00 +01:00
|
|
|
|
(
|
|
|
|
|
|
0,
|
|
|
|
|
|
{},
|
|
|
|
|
|
'phone number',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
1,
|
2022-12-22 22:11:07 -05:00
|
|
|
|
{'phone number': '2020900123'},
|
2019-05-03 13:07:00 +01:00
|
|
|
|
'one',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
2,
|
2022-12-22 22:11:07 -05:00
|
|
|
|
{'phone number': '2020900123', 'one': 'one'},
|
2019-05-03 13:07:00 +01:00
|
|
|
|
'two',
|
|
|
|
|
|
),
|
|
|
|
|
|
])
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_shows_placeholders_in_correct_order(
|
2019-05-03 13:07:00 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_has_no_jobs,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
step_index,
|
|
|
|
|
|
prefilled,
|
|
|
|
|
|
expected_field_label,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = prefilled
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2019-05-03 13:07:00 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=step_index,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('label').text) == expected_field_label
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-08 09:10:04 +00:00
|
|
|
|
@pytest.mark.parametrize('user, template_type, expected_link_text, expected_link_url', [
|
2018-06-14 15:04:01 +01:00
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_with_permissions(),
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'sms',
|
2018-06-14 15:04:01 +01:00
|
|
|
|
'Use my phone number',
|
2020-10-05 16:16:11 +01:00
|
|
|
|
partial(url_for, 'main.send_one_off_to_myself')
|
2018-06-14 15:04:01 +01:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_with_permissions(),
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'email',
|
2018-06-14 15:04:01 +01:00
|
|
|
|
'Use my email address',
|
2020-10-05 16:16:11 +01:00
|
|
|
|
partial(url_for, 'main.send_one_off_to_myself')
|
2018-06-14 15:04:01 +01:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user(),
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'sms',
|
2018-06-14 15:04:01 +01:00
|
|
|
|
None, None
|
|
|
|
|
|
),
|
2017-05-25 13:31:51 +01:00
|
|
|
|
])
|
|
|
|
|
|
def test_send_one_off_has_skip_link(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-05-25 13:31:51 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_email_template,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2017-05-25 13:31:51 +01:00
|
|
|
|
mocker,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
template_type,
|
2017-05-25 13:31:51 +01:00
|
|
|
|
expected_link_text,
|
|
|
|
|
|
expected_link_url,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
user,
|
2017-05-25 13:31:51 +01:00
|
|
|
|
):
|
2023-01-19 17:29:21 -05:00
|
|
|
|
client_request.login(user)
|
2020-01-08 09:10:04 +00:00
|
|
|
|
template_data = create_template(template_id=fake_uuid, template_type=template_type)
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value={'data': template_data})
|
2017-05-25 13:31:51 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=0,
|
|
|
|
|
|
_follow_redirects=True,
|
2017-05-25 13:31:51 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2020-03-15 14:56:52 +00:00
|
|
|
|
skip_links = page.select('form a')
|
2017-05-25 13:31:51 +01:00
|
|
|
|
|
|
|
|
|
|
if expected_link_text and expected_link_url:
|
2020-03-15 14:56:52 +00:00
|
|
|
|
assert skip_links[1].text.strip() == expected_link_text
|
|
|
|
|
|
assert skip_links[1]['href'] == expected_link_url(
|
2017-05-25 13:31:51 +01:00
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
else:
|
2020-03-15 14:56:52 +00:00
|
|
|
|
with pytest.raises(IndexError):
|
|
|
|
|
|
skip_links[1]
|
2017-05-25 13:31:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
2020-01-08 09:10:04 +00:00
|
|
|
|
@pytest.mark.parametrize('template_type, expected_sticky', [
|
|
|
|
|
|
('sms', False),
|
|
|
|
|
|
('email', True),
|
2018-12-07 10:34:58 +00:00
|
|
|
|
])
|
2020-03-10 15:12:19 +00:00
|
|
|
|
def test_send_one_off_has_sticky_header_for_email(
|
2018-12-07 10:34:58 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_has_no_jobs,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
template_type,
|
2018-12-07 10:34:58 +00:00
|
|
|
|
expected_sticky,
|
|
|
|
|
|
):
|
2020-03-10 15:12:19 +00:00
|
|
|
|
template_data = create_template(template_type=template_type, content='((body))')
|
2020-01-08 09:10:04 +00:00
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value={'data': template_data})
|
2018-12-07 10:34:58 +00:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=0,
|
|
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert bool(page.select('.js-stick-at-top-when-scrolling')) == expected_sticky
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
|
@pytest.mark.parametrize('user', (
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
create_active_caseworking_user(),
|
2018-06-12 16:17:20 +01:00
|
|
|
|
))
|
2017-11-09 16:09:00 +00:00
|
|
|
|
def test_skip_link_will_not_show_on_sms_one_off_if_service_has_no_mobile_number(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-11-09 16:09:00 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_template,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
user,
|
2017-11-09 16:09:00 +00:00
|
|
|
|
):
|
2019-05-23 15:27:35 +01:00
|
|
|
|
user['mobile_number'] = None
|
|
|
|
|
|
client_request.login(user)
|
2020-10-07 14:51:18 +01:00
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=0,
|
2017-11-09 16:09:00 +00:00
|
|
|
|
)
|
2020-10-07 14:51:18 +01:00
|
|
|
|
skip_link = page.findAll('a', text='Use my phone number')
|
|
|
|
|
|
assert not skip_link
|
2017-11-09 16:09:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-03-15 14:56:52 +00:00
|
|
|
|
@pytest.mark.parametrize('user', (
|
|
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
create_active_caseworking_user(),
|
2018-07-18 09:48:19 +01:00
|
|
|
|
))
|
|
|
|
|
|
def test_send_one_off_offers_link_to_upload(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_has_jobs,
|
|
|
|
|
|
user,
|
|
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
client_request.login(user)
|
2018-07-18 09:48:19 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
2023-06-08 13:12:00 -04:00
|
|
|
|
back_link = page.select_one('.usa-back-link')
|
2020-03-15 14:56:52 +00:00
|
|
|
|
link = page.select_one('form a')
|
2018-07-18 09:48:19 +01:00
|
|
|
|
|
2019-04-29 11:44:05 +01:00
|
|
|
|
assert back_link.text.strip() == 'Back'
|
|
|
|
|
|
|
2018-07-18 09:48:19 +01:00
|
|
|
|
assert link.text.strip() == 'Upload a list of phone numbers'
|
|
|
|
|
|
assert link['href'] == url_for(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-16 14:57:36 +00:00
|
|
|
|
def test_send_one_off_has_link_to_use_existing_list(
|
2020-03-15 15:54:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_has_jobs,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert [
|
|
|
|
|
|
(link.text, link['href']) for link in page.select('form a')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
(
|
|
|
|
|
|
'Upload a list of phone numbers',
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'Use my phone number',
|
|
|
|
|
|
url_for(
|
2020-10-05 16:16:11 +01:00
|
|
|
|
'main.send_one_off_to_myself',
|
2020-03-15 15:54:49 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-18 09:48:19 +01:00
|
|
|
|
@pytest.mark.parametrize('user', (
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
create_active_caseworking_user(),
|
2018-07-18 09:48:19 +01:00
|
|
|
|
))
|
|
|
|
|
|
def test_link_to_upload_not_offered_when_entering_personalisation(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_has_jobs,
|
2020-10-07 14:51:18 +01:00
|
|
|
|
user
|
2018-07-18 09:48:19 +01:00
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
client_request.login(user)
|
2018-07-18 09:48:19 +01:00
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '2029009009'
|
|
|
|
|
|
session['placeholders'] = {'phone number': '2029009009'}
|
2018-07-18 09:48:19 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2018-07-18 09:48:19 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2020-10-07 14:51:18 +01:00
|
|
|
|
step_index=1,
|
2018-07-18 09:48:19 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-01-05 14:35:37 -05:00
|
|
|
|
# We’re entering personalization
|
2018-07-18 09:48:19 +01:00
|
|
|
|
assert page.select_one('input[type=text]')['name'] == 'placeholder_value'
|
|
|
|
|
|
assert page.select_one('label[for=placeholder_value]').text.strip() == 'name'
|
2021-07-30 18:23:12 +01:00
|
|
|
|
# No ‘Upload’ link shown
|
|
|
|
|
|
assert len(page.select('main a')) == 0
|
2018-07-18 09:48:19 +01:00
|
|
|
|
assert 'Upload' not in page.select_one('main').text
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
|
@pytest.mark.parametrize('user', (
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
create_active_caseworking_user(),
|
2018-06-12 16:17:20 +01:00
|
|
|
|
))
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_redirects_to_end_if_step_out_of_bounds(
|
2018-07-18 09:48:19 +01:00
|
|
|
|
client_request,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2020-10-07 14:51:18 +01:00
|
|
|
|
mock_get_service_template_with_placeholders,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
fake_uuid,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
user,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
client_request.login(user)
|
2017-05-22 11:49:15 +01:00
|
|
|
|
|
2018-07-18 09:48:19 +01:00
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '2020900123'
|
|
|
|
|
|
session['placeholders'] = {'name': 'foo', 'phone number': '2020900123'}
|
2017-05-22 11:49:15 +01:00
|
|
|
|
|
2018-07-18 09:48:19 +01:00
|
|
|
|
client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2018-07-18 09:48:19 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=999,
|
2018-07-18 09:48:19 +01:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.check_notification',
|
2018-07-18 09:48:19 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
2017-05-22 11:49:15 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
|
@pytest.mark.parametrize('user', (
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
create_active_caseworking_user(),
|
2018-06-12 16:17:20 +01:00
|
|
|
|
))
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_redirects_to_start_if_you_skip_steps(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
mocker,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
user,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
):
|
2021-12-30 16:13:49 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2017-06-26 14:56:14 +01:00
|
|
|
|
session['placeholders'] = {'address_line_1': 'foo'}
|
2017-05-22 11:49:15 +01:00
|
|
|
|
|
2023-01-19 17:29:21 -05:00
|
|
|
|
client_request.login(user)
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2017-05-22 11:49:15 +01:00
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
2022-12-06 09:16:27 -05:00
|
|
|
|
step_index=7,
|
2021-12-30 16:13:49 +00:00
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.send_one_off',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
2017-05-22 11:49:15 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
|
@pytest.mark.parametrize('user', (
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
create_active_caseworking_user(),
|
2018-06-12 16:17:20 +01:00
|
|
|
|
))
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_redirects_to_start_if_index_out_of_bounds_and_some_placeholders_empty(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
mock_s3_download,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
user,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
):
|
2023-01-19 17:29:21 -05:00
|
|
|
|
client_request.login(user)
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2017-06-26 14:56:14 +01:00
|
|
|
|
session['placeholders'] = {'name': 'foo'}
|
2017-05-22 11:49:15 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=999,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
2017-05-22 11:49:15 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
|
@pytest.mark.parametrize('user', (
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
create_active_caseworking_user(),
|
2018-06-12 16:17:20 +01:00
|
|
|
|
))
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_sms_message_redirects(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
mocker,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
user,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
):
|
2023-01-19 17:29:21 -05:00
|
|
|
|
client_request.login(user)
|
2019-03-20 17:26:51 +00:00
|
|
|
|
template = {'data': {'template_type': 'sms', 'folder': None}}
|
2017-06-30 10:55:59 +01:00
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value=template)
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
template_id=fake_uuid,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_response=url_for(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=0,
|
|
|
|
|
|
)
|
2017-05-04 09:30:55 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
|
@pytest.mark.parametrize('user', (
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
create_active_caseworking_user(),
|
2018-06-12 16:17:20 +01:00
|
|
|
|
))
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_email_to_self_without_placeholders_redirects_to_check_page(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2016-03-02 17:02:41 +00:00
|
|
|
|
mocker,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
service_one,
|
2016-12-14 10:12:53 +00:00
|
|
|
|
mock_get_service_email_template_without_placeholders,
|
2016-03-03 09:30:30 +00:00
|
|
|
|
mock_s3_upload,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
fake_uuid,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
user,
|
2016-03-02 17:02:41 +00:00
|
|
|
|
):
|
2023-01-19 17:29:21 -05:00
|
|
|
|
client_request.login(user)
|
2018-06-12 16:17:20 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2017-06-26 17:09:51 +01:00
|
|
|
|
session['recipient'] = 'foo@bar.com'
|
2020-10-07 14:51:18 +01:00
|
|
|
|
session['placeholders'] = {'email address': 'foo@bar.com'}
|
2016-03-02 17:02:41 +00:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
step_index=1,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_follow_redirects=True,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
)
|
2019-03-26 12:35:32 +00:00
|
|
|
|
|
2018-08-06 11:20:50 +01:00
|
|
|
|
assert page.select('h1')[0].text.strip() == 'Preview of ‘Two week reminder’'
|
2016-03-02 17:02:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
2018-08-09 16:29:51 +01:00
|
|
|
|
@pytest.mark.parametrize('permissions, expected_back_link_endpoint, extra_args', (
|
|
|
|
|
|
(
|
|
|
|
|
|
{'send_messages', 'manage_templates'},
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
{'template_id': unchanging_fake_uuid}
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{'send_messages'},
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
{},
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{'send_messages', 'view_activity'},
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
{},
|
|
|
|
|
|
),
|
2018-06-12 16:17:20 +01:00
|
|
|
|
))
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_step_0_back_link(
|
2018-08-09 16:29:51 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
active_user_with_permissions,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2018-08-09 16:29:51 +01:00
|
|
|
|
permissions,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
expected_back_link_endpoint,
|
|
|
|
|
|
extra_args,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
):
|
2019-05-23 15:27:35 +01:00
|
|
|
|
active_user_with_permissions['permissions'][SERVICE_ONE_ID] = permissions
|
2018-08-09 16:29:51 +01:00
|
|
|
|
client_request.login(active_user_with_permissions)
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
2018-08-09 16:29:51 +01:00
|
|
|
|
with client_request.session_transaction() as session:
|
2020-10-07 14:51:18 +01:00
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
session['recipient'] = None
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
2018-08-09 16:29:51 +01:00
|
|
|
|
page = client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2018-08-09 16:29:51 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=unchanging_fake_uuid,
|
2020-10-07 14:51:18 +01:00
|
|
|
|
step_index=0
|
2017-05-04 09:30:55 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-06-08 13:12:00 -04:00
|
|
|
|
assert page.select('.usa-back-link')[0]['href'] == url_for(
|
2018-06-12 16:17:20 +01:00
|
|
|
|
expected_back_link_endpoint,
|
2018-08-09 16:29:51 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
**extra_args
|
2017-05-04 09:30:55 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_sms_message_back_link_with_multiple_placeholders(
|
2019-05-03 13:07:00 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
mock_has_no_jobs,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '2020900123'
|
|
|
|
|
|
session['placeholders'] = {'phone number': '2020900123', 'one': 'bar'}
|
2019-05-03 13:07:00 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2019-05-03 13:07:00 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=unchanging_fake_uuid,
|
|
|
|
|
|
step_index=2,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-06-08 13:12:00 -04:00
|
|
|
|
assert page.select_one('.usa-back-link')['href'] == url_for(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2019-05-03 13:07:00 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=unchanging_fake_uuid,
|
|
|
|
|
|
step_index=1,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_populates_field_from_session(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2017-06-26 14:56:14 +01:00
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
session['placeholders']['name'] = 'Jo'
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
template_id=fake_uuid,
|
2020-10-07 14:51:18 +01:00
|
|
|
|
step_index=1,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
|
|
|
|
|
assert page.select('input')[0]['value'] == 'Jo'
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_sms_message_puts_submitted_data_in_session(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
service_one,
|
2016-05-05 08:39:36 +01:00
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
fake_uuid,
|
2016-05-05 08:39:36 +01:00
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '202-867-5303'
|
|
|
|
|
|
session['placeholders'] = {'phone number': '202-867-5303'}
|
2016-05-05 08:39:36 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off_step',
|
2017-06-26 14:56:14 +01:00
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
2020-10-07 14:51:18 +01:00
|
|
|
|
step_index=1,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_data={'placeholder_value': 'Jo'},
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.check_notification',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
)
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
assert session['recipient'] == '202-867-5303'
|
|
|
|
|
|
assert session['placeholders'] == {'phone number': '202-867-5303', 'name': 'Jo'}
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
2020-10-07 14:51:18 +01:00
|
|
|
|
def test_send_one_off_clears_session(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
mocker,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
):
|
2019-03-20 17:26:51 +00:00
|
|
|
|
template = {'data': {'template_type': 'sms', 'folder': None}}
|
2017-06-30 10:55:59 +01:00
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value=template)
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '2028675301'
|
2017-06-26 14:56:14 +01:00
|
|
|
|
session['placeholders'] = {'foo': 'bar'}
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.get(
|
2020-10-07 14:51:18 +01:00
|
|
|
|
'main.send_one_off',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2017-06-26 17:09:51 +01:00
|
|
|
|
assert session['recipient'] is None
|
2017-06-26 14:56:14 +01:00
|
|
|
|
assert session['placeholders'] == {}
|
2016-05-05 08:39:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-02-18 17:03:32 +00:00
|
|
|
|
def test_download_example_csv(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2016-02-18 17:03:32 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
2016-02-26 12:11:55 +00:00
|
|
|
|
mock_get_service,
|
2018-06-08 12:49:29 +01:00
|
|
|
|
mock_get_service_template_with_placeholders_same_as_recipient,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
fake_uuid
|
2016-02-18 17:03:32 +00:00
|
|
|
|
):
|
2021-12-31 12:16:12 +00:00
|
|
|
|
response = client_request.get_response(
|
|
|
|
|
|
'main.get_example_csv',
|
|
|
|
|
|
service_id=fake_uuid,
|
|
|
|
|
|
template_id=fake_uuid,
|
2021-12-31 12:08:14 +00:00
|
|
|
|
follow_redirects=True,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
)
|
2018-06-08 12:49:29 +01:00
|
|
|
|
assert response.get_data(as_text=True) == (
|
|
|
|
|
|
'phone number,name,date\r\n'
|
2022-08-05 00:25:03 -07:00
|
|
|
|
'12223334444,example,example\r\n'
|
2018-06-08 12:49:29 +01:00
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
assert 'text/csv' in response.headers['Content-Type']
|
2016-02-18 17:03:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-02-22 17:17:18 +00:00
|
|
|
|
def test_upload_csvfile_with_valid_phone_shows_all_numbers(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2016-02-26 10:54:06 +00:00
|
|
|
|
mock_get_service_template,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_get_users_by_service,
|
2018-03-29 11:56:53 +01:00
|
|
|
|
mock_get_live_service,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-04-27 16:05:04 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mocker,
|
2016-02-22 17:17:18 +00:00
|
|
|
|
):
|
2016-01-13 22:34:36 +00:00
|
|
|
|
|
2016-03-07 18:47:05 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
2016-04-07 14:30:51 +01:00
|
|
|
|
return_value='\n'.join(['phone number'] + [
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'202 867 07{0:02d}'.format(final_two) for final_two in range(0, 53)
|
2016-04-07 14:30:51 +01:00
|
|
|
|
])
|
2016-03-07 18:47:05 +00:00
|
|
|
|
)
|
2021-06-23 15:56:05 +01:00
|
|
|
|
mock_get_notification_count = mocker.patch('app.service_api_client.get_notification_count', return_value=0)
|
2021-12-31 12:08:14 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO(''.encode('utf-8')), 'example.csv')},
|
|
|
|
|
|
_content_type='multipart/form-data',
|
|
|
|
|
|
_follow_redirects=True,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
)
|
2021-12-31 12:08:14 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-04-30 12:10:54 +01:00
|
|
|
|
assert 'file_uploads' not in session
|
2016-01-11 15:00:51 +00:00
|
|
|
|
|
2020-10-23 16:10:03 +01:00
|
|
|
|
assert mock_s3_set_metadata.call_count == 2
|
|
|
|
|
|
assert mock_s3_set_metadata.call_args_list[0] == mocker.call(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
original_file_name='example.csv'
|
|
|
|
|
|
)
|
|
|
|
|
|
assert mock_s3_set_metadata.call_args_list[1] == mocker.call(
|
2018-04-27 16:05:04 +01:00
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
notification_count=53,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
valid=True,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
original_file_name='example.csv',
|
2018-04-27 16:05:04 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2022-12-22 22:11:07 -05:00
|
|
|
|
assert '202 867 0701' in page.text
|
|
|
|
|
|
assert '202 867 0749' in page.text
|
|
|
|
|
|
assert '202 867 0750' not in page.text
|
2021-12-31 12:08:14 +00:00
|
|
|
|
assert 'Only showing the first 50 rows' in page.text
|
2016-01-11 15:00:51 +00:00
|
|
|
|
|
2023-06-01 12:33:57 -06:00
|
|
|
|
mock_get_notification_count.assert_called_with(service_id=service_one['id'])
|
2016-06-17 11:54:01 +01:00
|
|
|
|
|
2016-01-11 15:00:51 +00:00
|
|
|
|
|
2020-01-07 10:47:00 +00:00
|
|
|
|
@pytest.mark.parametrize('international_sms_permission, should_allow_international', [
|
|
|
|
|
|
(False, False),
|
|
|
|
|
|
(True, True),
|
2017-04-26 16:19:49 +01:00
|
|
|
|
])
|
|
|
|
|
|
def test_upload_csvfile_with_international_validates(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2017-04-26 16:19:49 +01:00
|
|
|
|
mock_get_service_template,
|
2020-10-23 16:10:03 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2017-04-26 16:19:49 +01:00
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2017-04-26 16:19:49 +01:00
|
|
|
|
fake_uuid,
|
2020-01-07 10:47:00 +00:00
|
|
|
|
international_sms_permission,
|
2017-04-26 16:19:49 +01:00
|
|
|
|
should_allow_international,
|
2020-01-07 10:47:00 +00:00
|
|
|
|
service_one,
|
2017-04-26 16:19:49 +01:00
|
|
|
|
):
|
2020-01-07 10:47:00 +00:00
|
|
|
|
if international_sms_permission:
|
|
|
|
|
|
service_one['permissions'] += ('sms', 'international_sms')
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_service', return_value={'data': service_one})
|
2017-04-26 16:19:49 +01:00
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value='')
|
|
|
|
|
|
mock_recipients = mocker.patch(
|
|
|
|
|
|
'app.main.views.send.RecipientCSV',
|
2020-04-19 22:46:13 +01:00
|
|
|
|
return_value=RecipientCSV("", template=SMSPreviewTemplate(
|
|
|
|
|
|
{'content': 'foo', 'template_type': 'sms'}
|
|
|
|
|
|
)),
|
2017-04-26 16:19:49 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=fake_uuid,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'file': (BytesIO(''.encode('utf-8')), 'example.csv')},
|
|
|
|
|
|
_content_type='multipart/form-data',
|
|
|
|
|
|
_follow_redirects=True,
|
2017-04-26 16:19:49 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2020-04-27 10:57:25 +01:00
|
|
|
|
assert mock_recipients.call_args[1]['allow_international_sms'] == should_allow_international
|
2017-04-26 16:19:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-08-30 09:27:24 +01:00
|
|
|
|
def test_test_message_can_only_be_sent_now(
|
2018-05-03 13:35:59 +01:00
|
|
|
|
client_request,
|
2016-08-30 09:27:24 +01:00
|
|
|
|
mocker,
|
2017-05-22 10:32:22 +01:00
|
|
|
|
service_one,
|
2016-08-30 09:27:24 +01:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_s3_download,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-04-27 16:05:04 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2016-08-30 09:27:24 +01:00
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
2018-05-03 13:35:59 +01:00
|
|
|
|
content = client_request.get(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'main.check_messages',
|
2017-05-22 10:32:22 +01:00
|
|
|
|
service_id=service_one['id'],
|
2017-02-03 12:07:21 +00:00
|
|
|
|
upload_id=fake_uuid,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
from_test=True
|
2018-05-03 13:35:59 +01:00
|
|
|
|
)
|
2017-04-26 10:49:51 +01:00
|
|
|
|
|
|
|
|
|
|
assert 'name="scheduled_for"' not in content
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-13 13:29:49 +00:00
|
|
|
|
def test_send_button_is_correctly_labelled(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
fake_uuid,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2019-11-13 13:29:49 +00:00
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value='\n'.join(
|
2022-12-22 22:11:07 -05:00
|
|
|
|
['phone_number'] + (['2028670123'] * 1000)
|
2019-11-13 13:29:49 +00:00
|
|
|
|
))
|
|
|
|
|
|
mocker.patch('app.main.views.send.set_metadata_on_csv_upload')
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(
|
2019-12-20 13:51:15 +00:00
|
|
|
|
page.select_one('main [type=submit]').text
|
2019-11-13 13:29:49 +00:00
|
|
|
|
) == (
|
|
|
|
|
|
'Send 1,000 text messages'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-22 10:32:22 +01:00
|
|
|
|
@pytest.mark.parametrize('when', [
|
|
|
|
|
|
'', '2016-08-25T13:04:21.767198'
|
|
|
|
|
|
])
|
2016-02-22 17:17:18 +00:00
|
|
|
|
def test_create_job_should_call_api(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2016-02-22 17:17:18 +00:00
|
|
|
|
mock_create_job,
|
|
|
|
|
|
mock_get_job,
|
2016-03-02 15:37:35 +00:00
|
|
|
|
mock_get_notifications,
|
2016-02-29 17:03:56 +00:00
|
|
|
|
mock_get_service_template,
|
2018-12-03 17:19:38 +00:00
|
|
|
|
mock_get_service_data_retention,
|
2016-05-24 12:34:29 +01:00
|
|
|
|
mocker,
|
2016-08-07 09:17:49 +01:00
|
|
|
|
fake_uuid,
|
2020-03-16 17:00:34 +00:00
|
|
|
|
when,
|
2016-02-22 17:17:18 +00:00
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
data = mock_get_job(SERVICE_ONE_ID, fake_uuid)['data']
|
2016-05-24 12:34:29 +01:00
|
|
|
|
job_id = data['id']
|
|
|
|
|
|
original_file_name = data['original_file_name']
|
|
|
|
|
|
template_id = data['template']
|
|
|
|
|
|
notification_count = data['notification_count']
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'template_id': template_id,
|
|
|
|
|
|
'notification_count': notification_count,
|
|
|
|
|
|
'valid': True
|
|
|
|
|
|
}
|
2017-02-03 12:07:21 +00:00
|
|
|
|
}
|
2018-03-13 16:29:20 +00:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.start_job',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
upload_id=job_id,
|
|
|
|
|
|
original_file_name=original_file_name,
|
2020-03-16 17:00:34 +00:00
|
|
|
|
_data={
|
|
|
|
|
|
'scheduled_for': when,
|
|
|
|
|
|
},
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
_expected_status=200,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
)
|
2016-01-29 10:27:23 +00:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
assert original_file_name in page.text
|
|
|
|
|
|
|
2016-08-25 13:27:24 +01:00
|
|
|
|
mock_create_job.assert_called_with(
|
|
|
|
|
|
job_id,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
SERVICE_ONE_ID,
|
2018-04-30 12:07:36 +01:00
|
|
|
|
scheduled_for=when,
|
2016-08-25 13:27:24 +01:00
|
|
|
|
)
|
2016-03-03 15:26:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-11-02 16:53:40 +00:00
|
|
|
|
@pytest.mark.parametrize('route, response_code', [
|
|
|
|
|
|
('main.send_messages', 200),
|
|
|
|
|
|
('main.get_example_csv', 200),
|
2020-10-07 14:51:18 +01:00
|
|
|
|
('main.send_one_off', 302)
|
2016-11-02 16:53:40 +00:00
|
|
|
|
])
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_route_permissions(
|
|
|
|
|
|
mocker,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2022-01-04 18:33:23 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
|
mock_create_job,
|
|
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
route,
|
|
|
|
|
|
response_code,
|
|
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
validate_route_permission(
|
|
|
|
|
|
mocker,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
"GET",
|
|
|
|
|
|
response_code,
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
route,
|
|
|
|
|
|
service_id=service_one['id'],
|
2017-02-28 12:16:35 +00:00
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
),
|
2018-02-28 17:22:20 +00:00
|
|
|
|
['view_activity', 'send_messages'],
|
2017-02-03 12:07:21 +00:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one)
|
2016-03-09 12:10:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-07-03 17:21:44 +01:00
|
|
|
|
@pytest.mark.parametrize('route, response_code, method', [
|
|
|
|
|
|
('main.check_notification', 200, 'GET'),
|
|
|
|
|
|
('main.send_notification', 302, 'POST')
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_route_permissions_send_check_notifications(
|
|
|
|
|
|
mocker,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2022-01-04 18:33:23 +00:00
|
|
|
|
client_request,
|
2017-07-03 17:21:44 +01:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_send_notification,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
route,
|
|
|
|
|
|
response_code,
|
|
|
|
|
|
method
|
|
|
|
|
|
):
|
2022-01-04 18:33:23 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '2028675301'
|
2017-07-03 17:21:44 +01:00
|
|
|
|
session['placeholders'] = {'name': 'a'}
|
|
|
|
|
|
validate_route_permission_with_client(
|
2017-10-18 14:51:26 +01:00
|
|
|
|
mocker,
|
2022-01-04 18:33:23 +00:00
|
|
|
|
client_request,
|
2017-10-18 14:51:26 +01:00
|
|
|
|
method,
|
|
|
|
|
|
response_code,
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
route,
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
),
|
2018-02-28 17:22:20 +00:00
|
|
|
|
['send_messages'],
|
2017-10-18 14:51:26 +01:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one
|
|
|
|
|
|
)
|
2017-07-03 17:21:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-08-06 11:09:57 +01:00
|
|
|
|
@pytest.mark.parametrize('route, expected_status', [
|
|
|
|
|
|
('main.send_messages', 403),
|
|
|
|
|
|
('main.get_example_csv', 403),
|
2020-10-07 14:51:18 +01:00
|
|
|
|
('main.send_one_off', 403),
|
2016-11-02 16:53:40 +00:00
|
|
|
|
])
|
2018-08-06 11:09:57 +01:00
|
|
|
|
def test_route_permissions_sending(
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mocker,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2022-01-04 18:33:23 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
|
mock_create_job,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
route,
|
2018-08-06 11:09:57 +01:00
|
|
|
|
expected_status,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
validate_route_permission(
|
|
|
|
|
|
mocker,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
"GET",
|
2018-08-06 11:09:57 +01:00
|
|
|
|
expected_status,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
url_for(
|
|
|
|
|
|
route,
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
template_id=fake_uuid),
|
|
|
|
|
|
['blah'],
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one)
|
2016-03-09 13:51:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-06-24 10:15:20 +01:00
|
|
|
|
@pytest.mark.parametrize(
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'template_type, has_placeholders, extra_args, expected_url',
|
2016-06-24 10:15:20 +01:00
|
|
|
|
[
|
|
|
|
|
|
(
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'sms',
|
|
|
|
|
|
False,
|
2016-06-24 10:15:20 +01:00
|
|
|
|
dict(),
|
2017-04-07 09:18:00 +01:00
|
|
|
|
partial(url_for, '.send_messages')
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'sms',
|
|
|
|
|
|
True,
|
2017-04-07 09:18:00 +01:00
|
|
|
|
dict(),
|
|
|
|
|
|
partial(url_for, '.send_messages')
|
|
|
|
|
|
),
|
2016-06-24 10:15:20 +01:00
|
|
|
|
(
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'sms',
|
|
|
|
|
|
True,
|
2017-04-07 09:18:00 +01:00
|
|
|
|
dict(from_test=True),
|
2020-10-07 14:51:18 +01:00
|
|
|
|
partial(url_for, '.send_one_off')
|
2016-06-24 10:15:20 +01:00
|
|
|
|
)
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
2016-06-24 10:25:35 +01:00
|
|
|
|
def test_check_messages_back_link(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2016-06-24 10:25:35 +01:00
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_has_permissions,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2016-06-24 10:25:35 +01:00
|
|
|
|
mock_s3_download,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-04-27 16:05:04 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2016-06-24 10:25:35 +01:00
|
|
|
|
fake_uuid,
|
2017-04-07 09:18:00 +01:00
|
|
|
|
mocker,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
template_type,
|
|
|
|
|
|
has_placeholders,
|
2016-06-24 10:25:35 +01:00
|
|
|
|
extra_args,
|
|
|
|
|
|
expected_url
|
|
|
|
|
|
):
|
2020-01-08 09:10:04 +00:00
|
|
|
|
content = 'Hi there ((name))' if has_placeholders else 'Hi there'
|
|
|
|
|
|
template_data = create_template(template_id=fake_uuid, template_type=template_type, content=content)
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value={'data': template_data})
|
2018-10-01 16:03:06 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'original_file_name': 'valid.csv',
|
|
|
|
|
|
'template_id': fake_uuid,
|
|
|
|
|
|
'notification_count': 1,
|
|
|
|
|
|
'valid': True
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'main.check_messages',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
upload_id=fake_uuid,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_test_page_title=False,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
**extra_args
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2017-02-03 12:07:21 +00:00
|
|
|
|
assert (
|
2023-06-08 13:12:00 -04:00
|
|
|
|
page.find_all('a', {'class': 'usa-back-link'})[0]['href']
|
2019-03-26 12:35:32 +00:00
|
|
|
|
) == expected_url(service_id=SERVICE_ONE_ID, template_id=fake_uuid)
|
2016-06-17 11:54:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-08-10 15:55:13 +01:00
|
|
|
|
@pytest.mark.parametrize('num_requested,expected_msg', [
|
2021-06-23 15:56:05 +01:00
|
|
|
|
(None, '‘example.csv’ contains 1,234 phone numbers.'),
|
|
|
|
|
|
("0", '‘example.csv’ contains 1,234 phone numbers.'),
|
|
|
|
|
|
("1", 'You can still send 49 messages today, but ‘example.csv’ contains 1,234 phone numbers.')
|
|
|
|
|
|
], ids=['none_sent', 'none_sent', 'some_sent'])
|
2016-07-21 15:39:00 +01:00
|
|
|
|
def test_check_messages_shows_too_many_messages_errors(
|
|
|
|
|
|
mocker,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service, # set message_limit to 50
|
2016-07-21 15:39:00 +01:00
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_template,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2016-07-21 15:39:00 +01:00
|
|
|
|
fake_uuid,
|
2016-07-25 14:16:34 +01:00
|
|
|
|
num_requested,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
expected_msg,
|
|
|
|
|
|
mock_s3_get_metadata
|
2016-07-21 15:39:00 +01:00
|
|
|
|
):
|
|
|
|
|
|
# csv with 100 phone numbers
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value=',\n'.join(
|
2020-09-26 14:50:47 +01:00
|
|
|
|
['phone number'] + ([mock_get_users_by_service(None)[0]['mobile_number']] * 1234)
|
2016-07-21 15:39:00 +01:00
|
|
|
|
))
|
2021-06-23 15:56:05 +01:00
|
|
|
|
mocker.patch('app.extensions.redis_client.get', return_value=num_requested)
|
2016-07-21 15:39:00 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'template_id': fake_uuid,
|
|
|
|
|
|
'notification_count': 1,
|
|
|
|
|
|
'valid': True
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'main.check_messages',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2016-07-21 15:39:00 +01:00
|
|
|
|
assert page.find('h1').text.strip() == 'Too many recipients'
|
|
|
|
|
|
assert page.find('div', class_='banner-dangerous').find('a').text.strip() == 'trial mode'
|
|
|
|
|
|
|
|
|
|
|
|
# remove excess whitespace from element
|
2020-02-17 15:36:46 +00:00
|
|
|
|
details = page.find('div', class_='banner-dangerous').find_all('p')[1]
|
2016-07-21 15:39:00 +01:00
|
|
|
|
details = ' '.join([line.strip() for line in details.text.split('\n') if line.strip() != ''])
|
2016-08-10 15:55:13 +01:00
|
|
|
|
assert details == expected_msg
|
2016-10-14 10:44:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-01-23 17:05:41 +00:00
|
|
|
|
def test_check_messages_shows_trial_mode_error(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2017-01-23 17:05:41 +00:00
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_has_permissions,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2018-03-13 16:29:20 +00:00
|
|
|
|
fake_uuid,
|
2017-01-23 17:05:41 +00:00
|
|
|
|
mocker
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value=(
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'phone number,\n2028675209' # Not in team
|
2017-01-23 17:05:41 +00:00
|
|
|
|
))
|
2018-03-13 16:29:20 +00:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'template_id': '',
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2017-01-23 17:05:41 +00:00
|
|
|
|
'main.check_messages',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2017-01-23 17:05:41 +00:00
|
|
|
|
assert ' '.join(
|
|
|
|
|
|
page.find('div', class_='banner-dangerous').text.split()
|
|
|
|
|
|
) == (
|
2019-09-13 09:35:05 +01:00
|
|
|
|
'You cannot send to this phone number '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'In trial mode you can only send to yourself and members of your team'
|
2017-01-23 17:05:41 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-02-04 14:08:11 +00:00
|
|
|
|
@pytest.mark.parametrize('uploaded_file_name', (
|
|
|
|
|
|
pytest.param('applicants.ods'), # normal job
|
|
|
|
|
|
pytest.param('send_me_later.csv'), # should look at scheduled job
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_warns_if_file_sent_already(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
uploaded_file_name,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value=(
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'phone number,\n2028675209'
|
2019-02-04 14:08:11 +00:00
|
|
|
|
))
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_csv_metadata',
|
|
|
|
|
|
return_value={'original_file_name': uploaded_file_name},
|
|
|
|
|
|
)
|
2019-02-04 14:08:11 +00:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id="5d729fbd-239c-44ab-b498-75a985f3198f",
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
original_file_name=uploaded_file_name,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select_one('.banner-dangerous').text
|
|
|
|
|
|
) == (
|
2019-02-05 15:07:19 +00:00
|
|
|
|
'These messages have already been sent today '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'If you need to resend them, rename the file and upload it again.'
|
2019-02-04 14:08:11 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mock_get_jobs.assert_called_once_with(SERVICE_ONE_ID, limit_days=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-05-26 12:35:48 -07:00
|
|
|
|
@pytest.mark.parametrize('uploaded_file_name', (
|
|
|
|
|
|
pytest.param('thisisatest.csv'), # different template version
|
|
|
|
|
|
pytest.param('full_of_regret.csv'), # job is cancelled
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_warns_if_file_sent_already_errors(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
uploaded_file_name,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value=(
|
|
|
|
|
|
'phone number,\n2028675209'
|
|
|
|
|
|
))
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_csv_metadata',
|
|
|
|
|
|
return_value={'original_file_name': uploaded_file_name},
|
|
|
|
|
|
)
|
|
|
|
|
|
# Should be botocore.errorfactory.NoSuchKey but for some reason can't use that
|
|
|
|
|
|
with pytest.raises(expected_exception=Exception):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id="5d729fbd-239c-44ab-b498-75a985f3198f",
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
original_file_name=uploaded_file_name,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select_one('.banner-dangerous').text
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'These messages have already been sent today '
|
|
|
|
|
|
'If you need to resend them, rename the file and upload it again.'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mock_get_jobs.assert_called_once_with(SERVICE_ONE_ID, limit_days=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-03 14:08:25 +01:00
|
|
|
|
def test_check_messages_column_error_doesnt_show_optional_columns(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
2022-12-05 15:33:44 -05:00
|
|
|
|
mock_get_service_template,
|
2017-10-03 14:08:25 +01:00
|
|
|
|
mock_has_permissions,
|
2018-03-13 16:29:20 +00:00
|
|
|
|
fake_uuid,
|
2017-10-03 14:08:25 +01:00
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2017-10-03 14:08:25 +01:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value='\n'.join(
|
|
|
|
|
|
['address_line_1,address_line_2,foo'] +
|
|
|
|
|
|
['First Lastname,1 Example Road,SW1 1AA']
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'template_id': '',
|
|
|
|
|
|
'original_file_name': '',
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-03 14:08:25 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
2018-03-13 16:29:20 +00:00
|
|
|
|
upload_id=fake_uuid,
|
2017-10-03 14:08:25 +01:00
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.banner-dangerous').text) == (
|
2019-10-03 14:24:28 +01:00
|
|
|
|
'There’s a problem with your column names '
|
2022-12-05 15:33:44 -05:00
|
|
|
|
'Your file needs a column called ‘phone number’. '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'Right now it has columns called ‘address_line_1’, ‘address_line_2’ and ‘foo’.'
|
2017-10-03 14:08:25 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-06 14:22:22 +00:00
|
|
|
|
def test_check_messages_adds_sender_id_in_session_to_metadata(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-11-06 14:22:22 +00:00
|
|
|
|
mock_s3_set_metadata,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value=(
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'phone number,\n2028675209'
|
2018-11-06 14:22:22 +00:00
|
|
|
|
))
|
|
|
|
|
|
mocker.patch('app.main.views.send.get_sms_sender_from_session')
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {'template_id': fake_uuid}
|
|
|
|
|
|
}
|
|
|
|
|
|
session['sender_id'] = 'fake-sender'
|
|
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mock_s3_set_metadata.assert_called_once_with(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
notification_count=1,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
sender_id='fake-sender',
|
|
|
|
|
|
valid=True,
|
|
|
|
|
|
original_file_name='example.csv',
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-14 10:44:28 +01:00
|
|
|
|
def test_check_messages_shows_over_max_row_error(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2016-10-14 10:44:28 +01:00
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_has_permissions,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2016-10-14 10:44:28 +01:00
|
|
|
|
mock_s3_download,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker
|
|
|
|
|
|
):
|
|
|
|
|
|
mock_recipients = mocker.patch('app.main.views.send.RecipientCSV').return_value
|
|
|
|
|
|
mock_recipients.max_rows = 11111
|
|
|
|
|
|
mock_recipients.__len__.return_value = 99999
|
2016-10-17 10:20:14 +01:00
|
|
|
|
mock_recipients.too_many_rows.return_value = True
|
2016-10-14 10:44:28 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'template_id': fake_uuid,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2016-10-14 10:44:28 +01:00
|
|
|
|
'main.check_messages',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2016-10-14 10:44:28 +01:00
|
|
|
|
assert ' '.join(
|
|
|
|
|
|
page.find('div', class_='banner-dangerous').text.split()
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'Your file has too many rows '
|
|
|
|
|
|
'Notify can process up to 11,111 rows at once. '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'Your file has 99,999 rows.'
|
2016-10-14 10:44:28 +01:00
|
|
|
|
)
|
2017-01-19 14:55:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-06-26 17:09:51 +01:00
|
|
|
|
@pytest.mark.parametrize('existing_session_items', [
|
|
|
|
|
|
{},
|
2022-12-22 22:11:07 -05:00
|
|
|
|
{'recipient': '2028675301'},
|
2017-06-26 17:09:51 +01:00
|
|
|
|
{'name': 'Jo'}
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_check_notification_redirects_if_session_not_populated(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-26 17:09:51 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
existing_session_items,
|
|
|
|
|
|
mock_get_service_template_with_placeholders
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2017-06-26 17:09:51 +01:00
|
|
|
|
session.update(existing_session_items)
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.get(
|
2017-06-26 17:09:51 +01:00
|
|
|
|
'main.check_notification',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-06-26 17:09:51 +01:00
|
|
|
|
template_id=fake_uuid,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_expected_status=301,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=1,
|
|
|
|
|
|
)
|
2017-06-26 17:09:51 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_notification_shows_preview(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_template
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '2028675301'
|
2017-06-26 17:09:51 +01:00
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_notification',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2018-08-06 11:20:50 +01:00
|
|
|
|
assert page.h1.text.strip() == 'Preview of ‘Two week reminder’'
|
2017-06-26 17:09:51 +01:00
|
|
|
|
assert (
|
2023-06-08 13:12:00 -04:00
|
|
|
|
page.find_all('a', {'class': 'usa-back-link'})[0]['href']
|
2018-06-12 16:17:20 +01:00
|
|
|
|
) == url_for(
|
2018-06-13 14:32:52 +01:00
|
|
|
|
'main.send_one_off_step',
|
2018-06-12 16:17:20 +01:00
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
2018-06-13 14:32:52 +01:00
|
|
|
|
step_index=0,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
)
|
2017-06-26 17:09:51 +01:00
|
|
|
|
|
2017-06-30 11:49:03 +01:00
|
|
|
|
# assert tour not visible
|
|
|
|
|
|
assert not page.select('.banner-tour')
|
2020-10-05 11:55:15 +01:00
|
|
|
|
|
|
|
|
|
|
# post to send_notification with help=0 to ensure no back link is then shown
|
2017-06-30 11:49:03 +01:00
|
|
|
|
assert page.form.attrs['action'] == url_for(
|
|
|
|
|
|
'main.send_notification',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
help='0'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-30 14:24:50 +00:00
|
|
|
|
@pytest.mark.parametrize('template, recipient, placeholders, expected_personalisation', (
|
|
|
|
|
|
(
|
|
|
|
|
|
mock_get_service_template,
|
2022-12-22 22:11:07 -05:00
|
|
|
|
'2028675301',
|
2018-10-30 14:24:50 +00:00
|
|
|
|
{'a': 'b'},
|
|
|
|
|
|
{'a': 'b'},
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
'test@example.com',
|
|
|
|
|
|
{},
|
|
|
|
|
|
{},
|
|
|
|
|
|
),
|
|
|
|
|
|
))
|
2017-06-26 17:09:51 +01:00
|
|
|
|
def test_send_notification_submits_data(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_send_notification,
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_template,
|
2018-10-30 14:24:50 +00:00
|
|
|
|
template,
|
|
|
|
|
|
recipient,
|
|
|
|
|
|
placeholders,
|
|
|
|
|
|
expected_personalisation,
|
2017-06-26 17:09:51 +01:00
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2018-10-30 14:24:50 +00:00
|
|
|
|
session['recipient'] = recipient
|
|
|
|
|
|
session['placeholders'] = placeholders
|
2017-06-26 17:09:51 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.send_notification',
|
2018-10-30 14:24:50 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-06-26 17:09:51 +01:00
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mock_send_notification.assert_called_once_with(
|
2018-10-30 14:24:50 +00:00
|
|
|
|
SERVICE_ONE_ID,
|
2017-06-26 17:09:51 +01:00
|
|
|
|
template_id=fake_uuid,
|
2018-10-30 14:24:50 +00:00
|
|
|
|
recipient=recipient,
|
|
|
|
|
|
personalisation=expected_personalisation,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
sender_id=None
|
2017-06-26 17:09:51 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_send_notification_clears_session(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_send_notification,
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_template,
|
2017-06-26 17:09:51 +01:00
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '2028675301'
|
2017-06-26 17:09:51 +01:00
|
|
|
|
session['placeholders'] = {'a': 'b'}
|
|
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.send_notification',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
assert 'recipient' not in session
|
|
|
|
|
|
assert 'placeholders' not in session
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-02-18 12:38:02 +00:00
|
|
|
|
@pytest.mark.parametrize('session_data', [
|
|
|
|
|
|
{'placeholders': {'a': 'b'}}, # missing recipient
|
|
|
|
|
|
{'recipient': '123'}, # missing placeholders
|
|
|
|
|
|
{'placeholders': {}, 'recipient': ''}, # missing address
|
|
|
|
|
|
])
|
2017-06-26 17:09:51 +01:00
|
|
|
|
def test_send_notification_redirects_if_missing_data(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-26 17:09:51 +01:00
|
|
|
|
fake_uuid,
|
2022-02-18 12:38:02 +00:00
|
|
|
|
session_data,
|
2017-06-26 17:09:51 +01:00
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2022-02-18 12:38:02 +00:00
|
|
|
|
session.update(session_data)
|
2017-06-26 17:09:51 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.send_notification',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-06-26 17:09:51 +01:00
|
|
|
|
template_id=fake_uuid,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
2017-06-26 17:09:51 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-30 11:49:03 +01:00
|
|
|
|
@pytest.mark.parametrize('extra_args, extra_redirect_args', [
|
|
|
|
|
|
({}, {}),
|
|
|
|
|
|
({'help': '3'}, {'help': '3'})
|
|
|
|
|
|
])
|
2017-06-26 17:09:51 +01:00
|
|
|
|
def test_send_notification_redirects_to_view_page(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-26 17:09:51 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_send_notification,
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_template,
|
2017-06-30 11:49:03 +01:00
|
|
|
|
extra_args,
|
|
|
|
|
|
extra_redirect_args
|
2017-06-26 17:09:51 +01:00
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '2028675301'
|
2017-06-26 17:09:51 +01:00
|
|
|
|
session['placeholders'] = {'a': 'b'}
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.send_notification',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'.view_notification',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
**extra_redirect_args
|
|
|
|
|
|
),
|
|
|
|
|
|
**extra_args
|
2017-06-26 17:09:51 +01:00
|
|
|
|
)
|
2017-06-29 15:31:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-06-29 16:06:36 +01:00
|
|
|
|
TRIAL_MODE_MSG = (
|
2019-09-13 09:35:05 +01:00
|
|
|
|
'Cannot send to this recipient when service is in trial mode – '
|
2017-06-29 16:06:36 +01:00
|
|
|
|
'see https://www.notifications.service.gov.uk/trial-mode'
|
|
|
|
|
|
)
|
2020-04-27 10:27:43 +01:00
|
|
|
|
TOO_LONG_MSG = 'Text messages cannot be longer than 918 characters. Your message is 954 characters.'
|
2017-06-29 16:06:36 +01:00
|
|
|
|
SERVICE_DAILY_LIMIT_MSG = 'Exceeded send limits (1000) for today'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('exception_msg, expected_h1, expected_err_details', [
|
|
|
|
|
|
(
|
|
|
|
|
|
TRIAL_MODE_MSG,
|
2019-09-13 09:35:05 +01:00
|
|
|
|
'You cannot send to this phone number',
|
2017-06-29 16:06:36 +01:00
|
|
|
|
'In trial mode you can only send to yourself and members of your team'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
TOO_LONG_MSG,
|
|
|
|
|
|
'Message too long',
|
2020-04-27 10:27:43 +01:00
|
|
|
|
'Text messages cannot be longer than 918 characters. Your message is 954 characters.'
|
2017-06-29 16:06:36 +01:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
SERVICE_DAILY_LIMIT_MSG,
|
|
|
|
|
|
'Daily limit reached',
|
2020-09-26 14:50:47 +01:00
|
|
|
|
'You can only send 1,000 messages per day in trial mode.'
|
2017-06-29 16:06:36 +01:00
|
|
|
|
),
|
|
|
|
|
|
])
|
2017-06-29 15:31:44 +01:00
|
|
|
|
def test_send_notification_shows_error_if_400(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
2017-06-29 16:06:36 +01:00
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
exception_msg,
|
|
|
|
|
|
expected_h1,
|
|
|
|
|
|
expected_err_details
|
2017-06-29 15:31:44 +01:00
|
|
|
|
):
|
2017-07-27 16:28:49 +01:00
|
|
|
|
|
|
|
|
|
|
class MockHTTPError(HTTPError):
|
|
|
|
|
|
message = exception_msg
|
|
|
|
|
|
|
2017-06-29 15:31:44 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.notification_api_client.send_notification',
|
2017-07-27 16:28:49 +01:00
|
|
|
|
side_effect=MockHTTPError(),
|
2017-06-29 15:31:44 +01:00
|
|
|
|
)
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '2028675301'
|
2020-04-27 10:27:43 +01:00
|
|
|
|
session['placeholders'] = {'name': 'a' * 900}
|
2017-06-29 15:31:44 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_notification',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=200
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2017-07-25 22:57:01 +01:00
|
|
|
|
assert normalize_spaces(page.select('.banner-dangerous h1')[0].text) == expected_h1
|
|
|
|
|
|
assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == expected_err_details
|
2017-06-29 16:06:36 +01:00
|
|
|
|
assert not page.find('input[type=submit]')
|
2017-07-25 23:06:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_send_notification_shows_email_error_in_trial_mode(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
):
|
2017-07-27 16:28:49 +01:00
|
|
|
|
class MockHTTPError(HTTPError):
|
|
|
|
|
|
message = TRIAL_MODE_MSG
|
|
|
|
|
|
status_code = 400
|
|
|
|
|
|
|
2017-07-25 23:06:55 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.notification_api_client.send_notification',
|
2017-07-27 16:28:49 +01:00
|
|
|
|
side_effect=MockHTTPError(),
|
2017-07-25 23:06:55 +01:00
|
|
|
|
)
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = 'test@example.com'
|
|
|
|
|
|
session['placeholders'] = {'date': 'foo', 'thing': 'bar'}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_notification',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select('.banner-dangerous h1')[0].text) == (
|
2019-09-13 09:35:05 +01:00
|
|
|
|
'You cannot send to this email address'
|
2017-07-25 23:06:55 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == (
|
|
|
|
|
|
'In trial mode you can only send to yourself and members of your team'
|
|
|
|
|
|
)
|
2017-10-17 16:06:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('endpoint, extra_args', [
|
2018-03-29 17:01:35 +01:00
|
|
|
|
('main.check_messages', {
|
2020-10-21 13:07:59 +01:00
|
|
|
|
'template_id': uuid4(), 'upload_id': uuid4()
|
2018-03-29 17:01:35 +01:00
|
|
|
|
}),
|
|
|
|
|
|
('main.send_one_off_step', {
|
2018-09-26 16:41:04 +01:00
|
|
|
|
'template_id': uuid4(), 'step_index': 0
|
2018-03-29 17:01:35 +01:00
|
|
|
|
}),
|
2017-10-17 16:06:15 +01:00
|
|
|
|
])
|
|
|
|
|
|
@pytest.mark.parametrize('reply_to_address', [
|
|
|
|
|
|
None,
|
2018-09-26 16:41:04 +01:00
|
|
|
|
uuid4(),
|
2017-10-17 16:06:15 +01:00
|
|
|
|
])
|
|
|
|
|
|
def test_reply_to_is_previewed_if_chosen(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
mock_s3_download,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-04-27 16:05:04 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2017-10-17 16:06:15 +01:00
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2017-10-17 16:06:15 +01:00
|
|
|
|
get_default_reply_to_email_address,
|
2018-03-13 16:29:20 +00:00
|
|
|
|
fake_uuid,
|
2017-10-17 16:06:15 +01:00
|
|
|
|
endpoint,
|
|
|
|
|
|
extra_args,
|
|
|
|
|
|
reply_to_address,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value="""
|
|
|
|
|
|
email_address,date,thing
|
|
|
|
|
|
notify@digital.cabinet-office.gov.uk,foo,bar
|
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = 'notify@digital.cabinet-office.gov.uk'
|
|
|
|
|
|
session['placeholders'] = {}
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
2018-03-29 17:01:35 +01:00
|
|
|
|
fake_uuid: {'template_id': fake_uuid}
|
2017-10-17 16:06:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
session['sender_id'] = reply_to_address
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
endpoint,
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
**extra_args
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
email_meta = page.select_one('.email-message-meta').text
|
|
|
|
|
|
|
|
|
|
|
|
if reply_to_address:
|
|
|
|
|
|
assert 'test@example.com' in email_meta
|
|
|
|
|
|
else:
|
|
|
|
|
|
assert 'test@example.com' not in email_meta
|
2017-11-16 14:13:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('endpoint, extra_args', [
|
2018-09-26 16:41:04 +01:00
|
|
|
|
('main.check_messages', {'template_id': uuid4(), 'upload_id': uuid4()}),
|
|
|
|
|
|
('main.send_one_off_step', {'template_id': uuid4(), 'step_index': 0}),
|
2017-11-16 14:13:32 +00:00
|
|
|
|
])
|
|
|
|
|
|
@pytest.mark.parametrize('sms_sender', [
|
|
|
|
|
|
None,
|
2018-09-26 16:41:04 +01:00
|
|
|
|
uuid4(),
|
2017-11-16 14:13:32 +00:00
|
|
|
|
])
|
|
|
|
|
|
def test_sms_sender_is_previewed(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_s3_download,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-04-27 16:05:04 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2017-11-16 14:13:32 +00:00
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2017-11-16 14:13:32 +00:00
|
|
|
|
get_default_sms_sender,
|
2018-03-13 16:29:20 +00:00
|
|
|
|
fake_uuid,
|
2017-11-16 14:13:32 +00:00
|
|
|
|
endpoint,
|
|
|
|
|
|
extra_args,
|
|
|
|
|
|
sms_sender,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value="""
|
|
|
|
|
|
phone number,date,thing
|
2022-12-22 22:11:07 -05:00
|
|
|
|
2028675109,foo,bar
|
2017-11-16 14:13:32 +00:00
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
session['recipient'] = '2028675109'
|
2017-11-16 14:13:32 +00:00
|
|
|
|
session['placeholders'] = {}
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'template_id': fake_uuid,
|
|
|
|
|
|
'notification_count': 1,
|
|
|
|
|
|
'valid': True
|
|
|
|
|
|
}
|
2017-11-16 14:13:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
session['sender_id'] = sms_sender
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
endpoint,
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
**extra_args
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
sms_sender_on_page = page.select_one('.sms-message-sender')
|
|
|
|
|
|
|
|
|
|
|
|
if sms_sender:
|
|
|
|
|
|
assert sms_sender_on_page.text.strip() == 'From: GOVUK'
|
|
|
|
|
|
else:
|
|
|
|
|
|
assert not sms_sender_on_page
|
2018-04-30 12:55:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_redirects_to_template_if_job_exists_already(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
mock_get_job,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
original_file_name='example.csv',
|
|
|
|
|
|
_expected_status=301,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-03-13 14:38:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-10-05 16:16:11 +01:00
|
|
|
|
def test_send_to_myself_sets_placeholder_and_redirects_for_email(
|
|
|
|
|
|
mocker, client_request, fake_uuid, mock_get_service_email_template
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.send_one_off_to_myself',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_url=url_for(
|
|
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=1,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2022-08-05 00:25:03 -07:00
|
|
|
|
assert session['recipient'] == 'test@user.gsa.gov'
|
|
|
|
|
|
assert session['placeholders'] == {'email address': 'test@user.gsa.gov'}
|
2020-10-05 16:16:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_send_to_myself_sets_placeholder_and_redirects_for_sms(
|
|
|
|
|
|
mocker, client_request, fake_uuid, mock_get_service_template
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.send_one_off_to_myself',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_url=url_for(
|
|
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=1,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2022-12-22 22:11:07 -05:00
|
|
|
|
assert session['recipient'] == '202-867-5303'
|
|
|
|
|
|
assert session['placeholders'] == {'phone number': '202-867-5303'}
|