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
|
2020-03-13 14:38:43 +00:00
|
|
|
|
from unittest.mock import ANY
|
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
|
2020-03-13 17:51:22 +00:00
|
|
|
|
from freezegun import freeze_time
|
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
|
2018-02-20 11:22:17 +00:00
|
|
|
|
from notifications_utils.template import (
|
|
|
|
|
|
LetterImageTemplate,
|
|
|
|
|
|
LetterPreviewTemplate,
|
2020-04-19 22:46:13 +01:00
|
|
|
|
SMSPreviewTemplate,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
)
|
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 (
|
2020-04-09 14:33:47 +01:00
|
|
|
|
template_json,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
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,
|
|
|
|
|
|
mock_get_service_letter_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')
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.govuk-radios .govuk-hint').text) == "(Default)"
|
|
|
|
|
|
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')
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.govuk-radios .govuk-hint').text) == "(Default)"
|
|
|
|
|
|
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')
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.govuk-radios .govuk-hint').text) == "(Default)"
|
|
|
|
|
|
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(
|
2021-01-13 10:31:07 +00:00
|
|
|
|
page.select_one('.govuk-radios .govuk-hint').text) == "(Default and receives replies)"
|
|
|
|
|
|
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(
|
2021-01-13 10:31:07 +00:00
|
|
|
|
page.select_one('.govuk-radios .govuk-hint').text) == "(Default and receives replies)"
|
|
|
|
|
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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."
|
2019-04-29 11:44:05 +01:00
|
|
|
|
assert page.select(".govuk-back-link")[0].text == "Back"
|
|
|
|
|
|
assert page.select(".govuk-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
|
|
|
|
|
|
|
|
|
|
|
2020-04-27 10:57:25 +01:00
|
|
|
|
def test_example_spreadsheet_for_letters(
|
|
|
|
|
|
client_request,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
service_one,
|
2020-04-27 10:57:25 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_letter_template_with_placeholders,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2020-07-01 16:43:08 +01:00
|
|
|
|
service_one['permissions'] += ['letter']
|
2020-04-27 10:57:25 +01:00
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=1)
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.send_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert list(zip(*[
|
|
|
|
|
|
[normalize_spaces(cell.text) for cell in page.select('tbody tr')[row].select('td')]
|
|
|
|
|
|
for row in (0, 1)
|
|
|
|
|
|
])) == [
|
|
|
|
|
|
('1', '2'),
|
|
|
|
|
|
('address line 1', 'A. Name'),
|
|
|
|
|
|
('address line 2', '123 Example Street'),
|
2020-09-07 11:49:43 +01:00
|
|
|
|
('address line 3', 'XM4 5HQ'),
|
2020-04-27 10:57:25 +01:00
|
|
|
|
('address line 4', ''),
|
|
|
|
|
|
('address line 5', ''),
|
|
|
|
|
|
('address line 6', ''),
|
2020-09-07 11:49:43 +01:00
|
|
|
|
('address line 7', ''),
|
2020-04-27 10:57:25 +01:00
|
|
|
|
('name', 'example'),
|
|
|
|
|
|
('date', 'example'),
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-13 21:25:59 +01:00
|
|
|
|
@pytest.mark.parametrize(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
"filename, acceptable_file, expected_status",
|
|
|
|
|
|
list(zip(test_spreadsheet_files, repeat(True), repeat(302))) +
|
|
|
|
|
|
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"
|
|
|
|
|
|
"07739 468 050,Pete,Coral,tomato\r\n"
|
|
|
|
|
|
"07527 125 974,Not Pete,Magenta,Avacado\r\n"
|
|
|
|
|
|
"07512 058 823,Still Not Pete,Crimson,Pear"
|
|
|
|
|
|
)
|
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
|
|
|
|
|
|
+447700900986
|
|
|
|
|
|
+447700900986
|
|
|
|
|
|
"""
|
|
|
|
|
|
)
|
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
|
|
|
|
|
|
assert '+447700900986' in page.text
|
|
|
|
|
|
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
|
|
|
|
|
|
+447700900986, yes
|
|
|
|
|
|
+447700900986, no
|
|
|
|
|
|
"""
|
|
|
|
|
|
)
|
|
|
|
|
|
|
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',
|
|
|
|
|
|
'+447700900986 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
|
|
|
|
|
|
+447700900986, {big_placeholder}
|
|
|
|
|
|
+447700900987, {big_placeholder}
|
|
|
|
|
|
"""
|
|
|
|
|
|
)
|
|
|
|
|
|
|
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',
|
|
|
|
|
|
f'+447700900986 {big_placeholder}',
|
|
|
|
|
|
'3 Message is too long',
|
|
|
|
|
|
f'+447700900987 {big_placeholder}',
|
|
|
|
|
|
]
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-15 13:31:14 +01:00
|
|
|
|
def test_upload_csv_file_with_bad_postal_address_shows_check_page_with_errors(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2020-04-15 13:31:14 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_letter_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,
|
2020-04-15 13:31:14 +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-07-01 16:43:08 +01:00
|
|
|
|
service_one['permissions'] += ['letter']
|
2020-04-15 13:31:14 +01:00
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=9)
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
|
|
|
|
|
return_value='''
|
|
|
|
|
|
address line 1, address line 3, address line 6,
|
|
|
|
|
|
Firstname Lastname, 123 Example St., SW1A 1AA
|
|
|
|
|
|
Firstname Lastname, 123 Example St., SW!A !AA
|
2020-04-27 10:57:25 +01:00
|
|
|
|
Firstname Lastname, 123 Example St., France
|
2020-04-15 13:31:14 +01:00
|
|
|
|
, 123 Example St., SW!A !AA
|
|
|
|
|
|
"1\n2\n3\n4\n5\n6\n7\n8"
|
2020-07-28 13:44:14 +01:00
|
|
|
|
=Firstname Lastname, 123 Example St., SW1A 1AA
|
2020-04-15 13:31:14 +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-15 13:31:14 +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 fix 5 addresses.'
|
2020-04-15 13:31:14 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
normalize_spaces(row.text) for row in page.select('tbody tr')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
'3 Last line of the address must be a real UK postcode',
|
|
|
|
|
|
'Firstname Lastname 123 Example St. SW!A !AA',
|
|
|
|
|
|
|
2020-09-10 11:18:20 +01:00
|
|
|
|
'4 You do not have permission to send letters to other countries',
|
2020-04-27 10:57:25 +01:00
|
|
|
|
'Firstname Lastname 123 Example St. France',
|
|
|
|
|
|
|
|
|
|
|
|
'5 Address must be at least 3 lines long',
|
2020-04-15 13:31:14 +01:00
|
|
|
|
'123 Example St. SW!A !AA',
|
|
|
|
|
|
|
2020-04-27 10:57:25 +01:00
|
|
|
|
'6 Address must be no more than 7 lines long',
|
2020-04-15 13:31:14 +01:00
|
|
|
|
'1 2 3 4 5 6 7 8',
|
2020-07-28 13:44:14 +01:00
|
|
|
|
|
2021-05-25 09:14:49 +01:00
|
|
|
|
'7 Address lines must not start with any of the following characters: @ ( ) = [ ] ” \\ / , < > ~',
|
2020-07-28 13:44:14 +01:00
|
|
|
|
'=Firstname Lastname 123 Example St. SW1A 1AA',
|
2020-04-15 13:31:14 +01:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-27 10:57:25 +01:00
|
|
|
|
def test_upload_csv_file_with_international_letters_permission_shows_appropriate_errors(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2020-04-27 10:57:25 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_letter_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,
|
2020-04-27 10:57:25 +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-07-01 16:43:08 +01:00
|
|
|
|
service_one['permissions'] += ['letter', 'international_letters']
|
2020-04-27 10:57:25 +01:00
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=9)
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
|
|
|
|
|
return_value='''
|
|
|
|
|
|
address line 1, address line 3, address line 6,
|
|
|
|
|
|
Firstname Lastname, 123 Example St., SW1A 1AA
|
|
|
|
|
|
Firstname Lastname, 123 Example St., France
|
|
|
|
|
|
Firstname Lastname, 123 Example St., SW!A !AA
|
|
|
|
|
|
Firstname Lastname, 123 Example St., Not France
|
|
|
|
|
|
'''
|
|
|
|
|
|
)
|
|
|
|
|
|
|
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-27 10:57:25 +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 fix 2 addresses.'
|
2020-04-27 10:57:25 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
normalize_spaces(row.text) for row in page.select('tbody tr')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
'4 Last line of the address must be a UK postcode or another country',
|
|
|
|
|
|
'Firstname Lastname 123 Example St. SW!A !AA',
|
|
|
|
|
|
|
|
|
|
|
|
'5 Last line of the address must be a UK postcode or another country',
|
|
|
|
|
|
'Firstname Lastname 123 Example St. Not France',
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-07 15:17:03 +01:00
|
|
|
|
@pytest.mark.parametrize('row_index, expected_postage', (
|
|
|
|
|
|
(2, 'Postage: second class'),
|
|
|
|
|
|
(3, 'Postage: international'),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_upload_csv_file_with_international_letters_permission_shows_correct_postage(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_letter_template,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2020-09-07 15:17:03 +01:00
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
row_index,
|
|
|
|
|
|
expected_postage,
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] += ['letter', 'international_letters']
|
|
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=9)
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
|
|
|
|
|
return_value='''
|
|
|
|
|
|
address line 1, address line 3, address line 6,
|
|
|
|
|
|
Firstname Lastname, 123 Example St., SW1A 1AA
|
|
|
|
|
|
Firstname Lastname, 123 Example St., France
|
|
|
|
|
|
'''
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
row_index=row_index,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.letter-postage').text) == expected_postage
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-27 12:06:16 +00:00
|
|
|
|
@pytest.mark.parametrize('file_contents, expected_error,', [
|
|
|
|
|
|
(
|
|
|
|
|
|
"""
|
|
|
|
|
|
telephone,name
|
|
|
|
|
|
+447700900986
|
|
|
|
|
|
""",
|
|
|
|
|
|
(
|
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
|
|
|
|
|
|
+447700900986
|
|
|
|
|
|
""",
|
|
|
|
|
|
(
|
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
|
|
|
|
|
|
+447700900111,+447700900222,+447700900333,
|
|
|
|
|
|
""",
|
|
|
|
|
|
(
|
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
|
|
|
|
(
|
|
|
|
|
|
"+447700900986",
|
|
|
|
|
|
(
|
|
|
|
|
|
'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
|
|
|
|
|
|
+447700900986, example
|
|
|
|
|
|
, example
|
|
|
|
|
|
+447700900986, example
|
|
|
|
|
|
""",
|
|
|
|
|
|
(
|
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
|
|
|
|
|
|
+447700900986, example
|
|
|
|
|
|
+447700900986,
|
|
|
|
|
|
+447700900986, example
|
|
|
|
|
|
""",
|
|
|
|
|
|
(
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
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,
|
2017-12-06 22:04:58 +00:00
|
|
|
|
'To: 07700900001',
|
|
|
|
|
|
'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,
|
2017-12-06 22:04:58 +00:00
|
|
|
|
'To: 07700900001',
|
|
|
|
|
|
'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,
|
2017-12-06 22:04:58 +00:00
|
|
|
|
'To: 07700900003',
|
|
|
|
|
|
'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
|
2017-12-06 22:04:58 +00:00
|
|
|
|
07700900001, A, foo, foo, foo
|
|
|
|
|
|
07700900002, B, foo, foo, foo
|
2018-03-09 15:07:47 +00:00
|
|
|
|
07700900003, 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
|
|
|
|
(
|
2019-04-29 16:21:47 +01:00
|
|
|
|
'<td class="table-field-left-aligned"> <div class=""> 07700900001 </div> </td>',
|
|
|
|
|
|
'<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>'
|
|
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-04-29 16:21:47 +01:00
|
|
|
|
'<td class="table-field-left-aligned"> <div class=""> 07700900002 </div> </td>',
|
|
|
|
|
|
'<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>'
|
|
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-04-29 16:21:47 +01:00
|
|
|
|
'<td class="table-field-left-aligned"> <div class=""> 07700900003 </div> </td>',
|
|
|
|
|
|
'<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
|
2017-04-04 09:46:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-05-10 17:00:20 +01:00
|
|
|
|
def test_upload_valid_csv_only_sets_meta_if_filename_known(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
mock_get_service_letter_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-05-10 17:00:20 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2020-03-10 15:12:19 +00:00
|
|
|
|
mock_template_preview,
|
2018-05-10 17:00:20 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value="""
|
|
|
|
|
|
addressline1, addressline2, postcode
|
|
|
|
|
|
House , 1 Street , SW1A 1AA
|
|
|
|
|
|
""")
|
2018-10-01 16:03:06 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=5,
|
|
|
|
|
|
)
|
2018-05-10 17:00:20 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2019-11-29 11:40:49 +00:00
|
|
|
|
'no_cookie.check_messages_preview',
|
2018-05-10 17:00:20 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
filetype='pdf',
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert len(mock_s3_set_metadata.call_args_list) == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
07700900001, 07700900002, 07700900003
|
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
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) == (
|
|
|
|
|
|
'2 07700900003 07700900003 07700900003'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
07700900001, A, foo, foo, foo
|
|
|
|
|
|
07700900002, B, foo, foo, foo
|
|
|
|
|
|
07700900003, C, foo, foo, foo
|
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-07 14:51:18 +01:00
|
|
|
|
@pytest.mark.parametrize('template_type', ['sms', 'email', 'letter'])
|
|
|
|
|
|
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,
|
2020-03-16 14:57:36 +00:00
|
|
|
|
mock_get_no_contact_lists,
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
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."
|
2019-04-29 11:44:05 +01:00
|
|
|
|
assert page.select(".govuk-back-link")[0].text == "Back"
|
|
|
|
|
|
assert page.select(".govuk-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,
|
2020-03-16 14:57:36 +00:00
|
|
|
|
mock_get_no_contact_lists,
|
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
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
mocker.patch('app.user_api_client.get_user', return_value=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})
|
2019-05-21 15:44:27 +01:00
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=9)
|
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,
|
|
|
|
|
|
{'phone number': '07900900123'},
|
|
|
|
|
|
'one',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
2,
|
|
|
|
|
|
{'phone number': '07900900123', 'one': 'one'},
|
|
|
|
|
|
'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,
|
2020-03-16 14:57:36 +00:00
|
|
|
|
mock_get_no_contact_lists,
|
2019-05-03 13:07:00 +01:00
|
|
|
|
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_user_with_permissions(),
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'letter',
|
2018-06-14 15:04:01 +01:00
|
|
|
|
None, None
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
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,
|
2020-03-16 14:57:36 +00:00
|
|
|
|
mock_get_no_contact_lists,
|
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
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
mocker.patch('app.user_api_client.get_user', return_value=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})
|
2019-05-21 15:44:27 +01:00
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=9)
|
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),
|
2020-03-10 15:12:19 +00:00
|
|
|
|
('letter', False),
|
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-03-16 14:57:36 +00:00
|
|
|
|
mock_get_no_contact_lists,
|
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})
|
2019-05-21 15:44:27 +01:00
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=9)
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-10 15:12:19 +00:00
|
|
|
|
def test_send_one_off_has_sticky_header_for_letter_on_non_address_placeholders(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
):
|
|
|
|
|
|
template_data = create_template(template_type='letter', content='((body))')
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value={'data': template_data})
|
|
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=9)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = ''
|
|
|
|
|
|
session['placeholders'] = {
|
|
|
|
|
|
'address line 1': 'foo',
|
|
|
|
|
|
'address line 2': 'bar',
|
|
|
|
|
|
'address line 3': '',
|
|
|
|
|
|
'address line 4': '',
|
|
|
|
|
|
'address line 5': '',
|
|
|
|
|
|
'address line 6': '',
|
|
|
|
|
|
'postcode': 'SW1 1AA',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=7, # letter template has 7 placeholders – we’re at the end
|
|
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert page.select('.js-stick-at-top-when-scrolling')
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
2020-03-16 14:57:36 +00:00
|
|
|
|
mock_get_no_contact_lists,
|
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,
|
2020-03-16 14:57:36 +00:00
|
|
|
|
mock_get_no_contact_lists,
|
2018-07-18 09:48:19 +01:00
|
|
|
|
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,
|
|
|
|
|
|
)
|
2021-07-30 18:23:12 +01:00
|
|
|
|
back_link = page.select_one('.govuk-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,
|
2020-03-16 10:14:11 +00:00
|
|
|
|
mock_get_contact_lists,
|
2020-03-15 15:54:49 +00:00
|
|
|
|
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,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-12-31 14:03:54 +00:00
|
|
|
|
'Use an emergency list',
|
2020-03-15 15:54:49 +00:00
|
|
|
|
url_for(
|
|
|
|
|
|
'main.choose_from_contact_list',
|
|
|
|
|
|
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,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-16 10:14:11 +00:00
|
|
|
|
def test_no_link_to_use_existing_list_for_service_without_lists(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_has_jobs,
|
2021-04-20 12:22:28 +01:00
|
|
|
|
platform_admin_user,
|
2020-03-16 10:14:11 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.models.contact_list.ContactLists.client_method',
|
|
|
|
|
|
return_value=[],
|
|
|
|
|
|
)
|
2021-04-20 12:22:28 +01:00
|
|
|
|
client_request.login(platform_admin_user)
|
2020-03-16 10:14:11 +00:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
link.text for link in page.select('form a')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
'Upload a list of phone numbers',
|
|
|
|
|
|
'Use my phone number',
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
session['recipient'] = '07900900900'
|
|
|
|
|
|
session['placeholders'] = {'phone number': '07900900900'}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# We’re entering personalisation
|
|
|
|
|
|
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:
|
2020-10-07 14:51:18 +01:00
|
|
|
|
session['recipient'] = '07900900123'
|
|
|
|
|
|
session['placeholders'] = {'name': 'foo', 'phone number': '07900900123'}
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
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,
|
|
|
|
|
|
platform_admin_user,
|
2017-05-22 11:49:15 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
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
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
mocker.patch('app.user_api_client.get_user', return_value=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
|
|
|
|
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
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,
|
|
|
|
|
|
step_index=7, # letter template has 7 placeholders – we’re at the end
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
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
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
mocker.patch('app.user_api_client.get_user', return_value=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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
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
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
mocker.patch('app.user_api_client.get_user', return_value=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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
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
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
mocker.patch('app.user_api_client.get_user', return_value=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,
|
2020-10-07 14:51:18 +01:00
|
|
|
|
mock_get_contact_lists,
|
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
|
|
|
|
)
|
|
|
|
|
|
|
2019-04-29 11:44:05 +01:00
|
|
|
|
assert page.select('.govuk-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:
|
|
|
|
|
|
session['recipient'] = '07900900123'
|
|
|
|
|
|
session['placeholders'] = {'phone number': '07900900123', 'one': 'bar'}
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select_one('.govuk-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_letter_redirects_to_right_url(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
2018-04-04 17:10:22 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-04-04 17:10:22 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2020-05-15 13:55:04 +01:00
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=9)
|
2021-12-30 16:13:49 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-04-04 17:10:22 +01:00
|
|
|
|
session['recipient'] = ''
|
|
|
|
|
|
session['placeholders'] = {
|
|
|
|
|
|
'address line 1': 'foo',
|
|
|
|
|
|
'address line 2': 'bar',
|
|
|
|
|
|
'address line 3': '',
|
|
|
|
|
|
'address line 4': '',
|
|
|
|
|
|
'address line 5': '',
|
|
|
|
|
|
'address line 6': '',
|
2020-09-07 11:49:43 +01:00
|
|
|
|
'address line 7': 'SW1 1AA',
|
2018-04-04 17:10:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
client_request.get(
|
2018-04-04 17:10:22 +01:00
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=7, # letter template has 7 placeholders – we’re at the end
|
2021-12-30 16:13:49 +00:00
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.check_notification',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2018-04-04 17:10:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
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-03-12 13:56:35 +00:00
|
|
|
|
def test_send_one_off_back_link_populates_address_textarea(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_letter_template,
|
2020-03-12 13:56:35 +00:00
|
|
|
|
mock_template_preview,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
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
|
2020-03-12 13:56:35 +00:00
|
|
|
|
session['placeholders'] = {'address line 1': 'foo', 'address line 2': 'bar', 'address line 3': ''}
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
2020-03-12 13:56:35 +00:00
|
|
|
|
# imagine someone hit the back button to go from line 3 page to line 2 page
|
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,
|
|
|
|
|
|
step_index=2,
|
2020-03-12 13:56:35 +00:00
|
|
|
|
_follow_redirects=True
|
2017-05-04 09:30:55 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2020-03-12 13:56:35 +00:00
|
|
|
|
assert page.select_one('h1').text.strip() == 'Send ‘Two week reminder’'
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
2020-03-12 13:56:35 +00:00
|
|
|
|
form = page.select_one('form')
|
|
|
|
|
|
assert form.select_one('label').text.strip() == 'Address'
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
2020-03-12 13:56:35 +00:00
|
|
|
|
textarea = form.select_one('textarea')
|
|
|
|
|
|
assert textarea.attrs['name'] == 'address'
|
2020-04-22 17:49:03 +01:00
|
|
|
|
assert textarea.text == '\r\nfoo\nbar'
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
2020-04-09 14:33:47 +01:00
|
|
|
|
@pytest.mark.parametrize('placeholder', (
|
|
|
|
|
|
'address_line_1',
|
|
|
|
|
|
'address_line_2',
|
|
|
|
|
|
'address_line_3',
|
|
|
|
|
|
'address_line_4',
|
|
|
|
|
|
'address_line_5',
|
|
|
|
|
|
'address_line_6',
|
|
|
|
|
|
'address_line_7',
|
|
|
|
|
|
'postcode',
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_send_one_off_letter_copes_with_placeholder_from_address_block(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_template_preview,
|
2020-04-09 16:25:48 +01:00
|
|
|
|
no_letter_contact_blocks,
|
2020-04-09 14:33:47 +01:00
|
|
|
|
placeholder,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': template_json(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
name="Awkward letter",
|
|
|
|
|
|
type_="letter",
|
|
|
|
|
|
subject=f"Hello (({placeholder}))",
|
|
|
|
|
|
content="We need to talk about ((thing))",
|
|
|
|
|
|
)},
|
|
|
|
|
|
)
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_one_off_letter_address',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'address': '''
|
|
|
|
|
|
foo
|
|
|
|
|
|
bar
|
|
|
|
|
|
SW1A 1AA
|
|
|
|
|
|
'''},
|
|
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2020-04-09 15:45:30 +01:00
|
|
|
|
assert normalize_spaces(page.select_one('form label').text) == 'thing'
|
|
|
|
|
|
assert page.select_one('form input[type=text]')['name'] == 'placeholder_value'
|
2020-08-07 15:16:04 +01:00
|
|
|
|
assert page.select_one('form input[type=text]').get('value') is None
|
2020-04-09 15:45:30 +01:00
|
|
|
|
|
2020-04-09 14:33:47 +01:00
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
assert session['placeholders'] == {
|
|
|
|
|
|
'address_line_1': 'foo',
|
|
|
|
|
|
'address_line_2': 'bar',
|
|
|
|
|
|
'address_line_3': '',
|
|
|
|
|
|
'address_line_4': '',
|
|
|
|
|
|
'address_line_5': '',
|
|
|
|
|
|
'address_line_6': '',
|
|
|
|
|
|
'address_line_7': 'SW1A 1AA',
|
|
|
|
|
|
'postcode': 'SW1A 1AA',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 16:25:48 +01:00
|
|
|
|
back_link = page.select_one('.govuk-back-link')['href']
|
|
|
|
|
|
assert back_link == url_for(
|
|
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=1,
|
|
|
|
|
|
)
|
|
|
|
|
|
previous_page = client_request.get_url(back_link, _follow_redirects=True)
|
|
|
|
|
|
|
|
|
|
|
|
# We’ve skipped past the address placeholder and gone back to the
|
|
|
|
|
|
# address block
|
|
|
|
|
|
assert normalize_spaces(previous_page.select_one('form label').text) == 'Address'
|
|
|
|
|
|
|
2020-04-09 14:33:47 +01:00
|
|
|
|
|
2020-09-07 15:17:03 +01:00
|
|
|
|
@pytest.mark.parametrize('last_line, expected_postage', (
|
|
|
|
|
|
('France', 'Postage: international'),
|
|
|
|
|
|
('SW1A 1AA', 'Postage: second class'),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_send_one_off_letter_shows_international_postage(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_letter_template_with_placeholders,
|
|
|
|
|
|
mock_template_preview,
|
|
|
|
|
|
no_letter_contact_blocks,
|
|
|
|
|
|
last_line,
|
|
|
|
|
|
expected_postage,
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] += ['letter', 'international_letters']
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_one_off_letter_address',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'address': f'''
|
|
|
|
|
|
123 Example Street
|
|
|
|
|
|
Paris
|
|
|
|
|
|
{last_line}
|
|
|
|
|
|
'''},
|
|
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('form label').text) == 'name'
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.letter-postage').text) == expected_postage
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
2020-10-07 14:51:18 +01:00
|
|
|
|
mock_get_contact_lists,
|
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:
|
2017-06-26 17:09:51 +01:00
|
|
|
|
session['recipient'] = '07700 900762'
|
2020-10-07 14:51:18 +01:00
|
|
|
|
session['placeholders'] = {'phone number': '07700 900762'}
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
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:
|
2017-06-26 14:56:14 +01:00
|
|
|
|
assert session['recipient'] == '07700 900762'
|
2020-10-07 14:51:18 +01:00
|
|
|
|
assert session['placeholders'] == {'phone number': '07700 900762', 'name': 'Jo'}
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('filetype', ['pdf', 'png'])
|
|
|
|
|
|
def test_send_test_works_as_letter_preview(
|
|
|
|
|
|
filetype,
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2017-06-23 13:35:08 +01:00
|
|
|
|
service_one['permissions'] = ['letter']
|
2017-05-04 09:30:55 +01:00
|
|
|
|
mocker.patch('app.service_api_client.get_service', return_value={"data": service_one})
|
|
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=1)
|
|
|
|
|
|
mocked_preview = mocker.patch(
|
|
|
|
|
|
'app.main.views.send.TemplatePreview.from_utils_template',
|
|
|
|
|
|
return_value='foo'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
service_id = service_one['id']
|
|
|
|
|
|
template_id = fake_uuid
|
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': 'Jo Lastname'}
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
2021-12-31 12:16:12 +00:00
|
|
|
|
response = client_request.get_response(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
'no_cookie.send_test_preview',
|
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
|
template_id=template_id,
|
|
|
|
|
|
filetype=filetype,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_letter_template.assert_called_with(service_id, template_id, None)
|
2017-05-04 09:30:55 +01:00
|
|
|
|
|
|
|
|
|
|
assert response.get_data(as_text=True) == 'foo'
|
|
|
|
|
|
assert mocked_preview.call_args[0][0].id == template_id
|
|
|
|
|
|
assert type(mocked_preview.call_args[0][0]) == LetterImageTemplate
|
2020-04-02 17:21:27 +01:00
|
|
|
|
assert mocked_preview.call_args[0][0].values == {'addressline1': 'Jo Lastname'}
|
2017-05-04 09:30:55 +01:00
|
|
|
|
assert mocked_preview.call_args[0][1] == filetype
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
2017-06-26 14:56:14 +01:00
|
|
|
|
session['recipient'] = '07700900001'
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2020-03-10 15:12:19 +00:00
|
|
|
|
def test_send_one_off_redirects_to_letter_address(client_request, fake_uuid, mock_get_service_letter_template):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['placeholders'] = {'foo': 'some old data that we dont care about'}
|
|
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.send_one_off_letter_address',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
# make sure it cleared session first
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
assert session['recipient'] is None
|
|
|
|
|
|
assert session['placeholders'] == {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_send_one_off_letter_address_shows_form(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_template_preview,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.send_one_off_letter_address',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select_one('h1').text.strip() == 'Send ‘Two week reminder’'
|
|
|
|
|
|
|
|
|
|
|
|
form = page.select_one('form')
|
|
|
|
|
|
|
2021-11-04 11:28:31 +00:00
|
|
|
|
assert form['data-module'] == 'autofocus'
|
|
|
|
|
|
assert form['data-force-focus'] == 'True'
|
|
|
|
|
|
|
2020-03-10 15:12:19 +00:00
|
|
|
|
assert form.select_one('label').text.strip() == 'Address'
|
2021-11-04 11:28:31 +00:00
|
|
|
|
assert form.select_one('textarea')['name'] == 'address'
|
|
|
|
|
|
assert form.select_one('textarea')['data-module'] == 'enhanced-textbox'
|
|
|
|
|
|
assert form.select_one('textarea')['data-highlight-placeholders'] == 'false'
|
|
|
|
|
|
assert form.select_one('textarea')['rows'] == '4'
|
2020-03-10 15:12:19 +00:00
|
|
|
|
|
|
|
|
|
|
upload_link = form.select_one('a')
|
|
|
|
|
|
|
|
|
|
|
|
assert upload_link.text.strip() == 'Upload a list of addresses'
|
|
|
|
|
|
assert upload_link['href'] == url_for(
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert (
|
|
|
|
|
|
page.find_all('a', {'class': 'govuk-back-link'})[0]['href']
|
|
|
|
|
|
) == url_for('main.view_template', service_id=SERVICE_ONE_ID, template_id=fake_uuid)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(['form_data', 'expected_placeholders'], [
|
|
|
|
|
|
# minimal
|
2020-04-02 17:32:26 +01:00
|
|
|
|
('\n'.join(['a', 'b', 'sw1a1aa']), {
|
2020-04-02 17:21:27 +01:00
|
|
|
|
'address_line_1': 'a',
|
|
|
|
|
|
'address_line_2': 'b',
|
|
|
|
|
|
'address_line_3': '',
|
|
|
|
|
|
'address_line_4': '',
|
|
|
|
|
|
'address_line_5': '',
|
|
|
|
|
|
'address_line_6': '',
|
2020-04-02 17:32:26 +01:00
|
|
|
|
'address_line_7': 'SW1A 1AA',
|
|
|
|
|
|
'postcode': 'SW1A 1AA',
|
2020-03-10 15:12:19 +00:00
|
|
|
|
}),
|
|
|
|
|
|
# maximal
|
2020-04-02 17:32:26 +01:00
|
|
|
|
('\n'.join(['a', 'b', 'c', 'd', 'e', 'f', 'sw1a1aa']), {
|
2020-04-02 17:21:27 +01:00
|
|
|
|
'address_line_1': 'a',
|
|
|
|
|
|
'address_line_2': 'b',
|
|
|
|
|
|
'address_line_3': 'c',
|
|
|
|
|
|
'address_line_4': 'd',
|
|
|
|
|
|
'address_line_5': 'e',
|
|
|
|
|
|
'address_line_6': 'f',
|
2020-04-02 17:32:26 +01:00
|
|
|
|
'address_line_7': 'SW1A 1AA',
|
|
|
|
|
|
'postcode': 'SW1A 1AA',
|
2020-03-10 15:12:19 +00:00
|
|
|
|
}),
|
|
|
|
|
|
# it ignores empty lines and strips whitespace from each line.
|
|
|
|
|
|
# It also strips extra whitespace from the middle of lines.
|
2021-10-29 16:10:55 +01:00
|
|
|
|
('\n a\ta \n\n\n \n\n\n\nb b \r\n sw1a\u00A01aa \n\n', {
|
|
|
|
|
|
'address_line_1': 'a a',
|
2020-04-02 17:21:27 +01:00
|
|
|
|
'address_line_2': 'b b',
|
|
|
|
|
|
'address_line_3': '',
|
|
|
|
|
|
'address_line_4': '',
|
|
|
|
|
|
'address_line_5': '',
|
|
|
|
|
|
'address_line_6': '',
|
2020-04-02 17:32:26 +01:00
|
|
|
|
'address_line_7': 'SW1A 1AA',
|
|
|
|
|
|
'postcode': 'SW1A 1AA',
|
2020-03-10 15:12:19 +00:00
|
|
|
|
}),
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_send_one_off_letter_address_populates_address_fields_in_session(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_template_preview,
|
|
|
|
|
|
form_data,
|
|
|
|
|
|
expected_placeholders
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.send_one_off_letter_address',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'address': form_data},
|
|
|
|
|
|
# there are no additional placeholders so go straight to the check page
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.check_notification',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
assert session['placeholders'] == expected_placeholders
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-27 10:57:25 +01:00
|
|
|
|
@pytest.mark.parametrize('form_data, extra_permissions, expected_error_message', [
|
|
|
|
|
|
(
|
|
|
|
|
|
'',
|
|
|
|
|
|
[],
|
|
|
|
|
|
'Cannot be empty'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'a\n\n\n\nb',
|
|
|
|
|
|
[],
|
|
|
|
|
|
'Address must be at least 3 lines long',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'\n'.join(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']),
|
|
|
|
|
|
[],
|
|
|
|
|
|
'Address must be no more than 7 lines long'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'\n'.join(['a', 'b', 'c', 'd', 'e', 'f', 'g']),
|
|
|
|
|
|
[],
|
|
|
|
|
|
'Last line of the address must be a real UK postcode',
|
|
|
|
|
|
),
|
2020-09-10 11:18:20 +01:00
|
|
|
|
(
|
|
|
|
|
|
'\n'.join(['a', 'b', 'c', 'd', 'e', 'france']),
|
|
|
|
|
|
[],
|
|
|
|
|
|
'You do not have permission to send letters to other countries',
|
|
|
|
|
|
),
|
2020-04-27 10:57:25 +01:00
|
|
|
|
(
|
|
|
|
|
|
'\n'.join(['a', 'b', 'c', 'd', 'e', 'f', 'g']),
|
|
|
|
|
|
['international_letters'],
|
|
|
|
|
|
'Last line of the address must be a UK postcode or another country',
|
|
|
|
|
|
),
|
2020-07-28 13:44:14 +01:00
|
|
|
|
(
|
|
|
|
|
|
'a\n(b\nSW1A 1AA',
|
|
|
|
|
|
[],
|
2021-05-25 09:14:49 +01:00
|
|
|
|
'Address lines must not start with any of the following characters: @ ( ) = [ ] ” \\ / , < > ~',
|
2020-07-28 13:44:14 +01:00
|
|
|
|
),
|
2020-03-10 15:12:19 +00:00
|
|
|
|
])
|
|
|
|
|
|
def test_send_one_off_letter_address_rejects_bad_addresses(
|
|
|
|
|
|
client_request,
|
2020-04-27 10:57:25 +01:00
|
|
|
|
service_one,
|
2020-03-10 15:12:19 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_template_preview,
|
|
|
|
|
|
form_data,
|
2020-04-27 10:57:25 +01:00
|
|
|
|
extra_permissions,
|
2020-03-10 15:12:19 +00:00
|
|
|
|
expected_error_message
|
|
|
|
|
|
):
|
2020-04-27 10:57:25 +01:00
|
|
|
|
service_one['permissions'] += extra_permissions
|
|
|
|
|
|
|
2020-03-10 15:12:19 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.send_one_off_letter_address',
|
|
|
|
|
|
_data={'address': form_data},
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=200
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
error = page.select('form .error-message')
|
|
|
|
|
|
assert normalize_spaces(error[0].text) == expected_error_message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_send_one_off_letter_address_goes_to_next_placeholder(client_request, mock_template_preview, mocker):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {}
|
|
|
|
|
|
|
|
|
|
|
|
template_data = create_template(template_type='letter', content='((foo))')
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value={'data': template_data})
|
|
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.send_one_off_letter_address',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=template_data['id'],
|
2020-04-02 17:32:26 +01:00
|
|
|
|
_data={'address': 'a\nb\nSW1A 1AA'},
|
2020-03-10 15:12:19 +00:00
|
|
|
|
# step 0-6 represent address line 1-6 and postcode. step 7 is the first non address placeholder
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=template_data['id'],
|
|
|
|
|
|
step_index=7,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
'07700 900321,example,example\r\n'
|
|
|
|
|
|
)
|
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'] + [
|
|
|
|
|
|
'07700 9007{0:02d}'.format(final_two) for final_two in range(0, 53)
|
|
|
|
|
|
])
|
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
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
assert '07700 900701' in page.text
|
|
|
|
|
|
assert '07700 900749' in page.text
|
|
|
|
|
|
assert '07700 900750' not in page.text
|
|
|
|
|
|
assert 'Only showing the first 50 rows' in page.text
|
2016-01-11 15:00:51 +00:00
|
|
|
|
|
2021-06-23 15:56:05 +01:00
|
|
|
|
mock_get_notification_count.assert_called_once_with(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
|
|
|
|
|
|
|
|
|
|
|
2020-03-16 17:00:34 +00:00
|
|
|
|
def test_job_from_contact_list_knows_where_its_come_from(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_s3_download,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_get_jobs,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2020-03-16 17:00:34 +00:00
|
|
|
|
mock_s3_set_metadata,
|
|
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
contact_list_id=unchanging_fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert page.select_one(
|
|
|
|
|
|
'form input[type=hidden][name=contact_list_id]'
|
|
|
|
|
|
)['value'] == str(unchanging_fake_uuid)
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_letter_can_only_be_sent_now(
|
2018-05-03 13:35:59 +01:00
|
|
|
|
client_request,
|
2017-05-04 09:30:55 +01:00
|
|
|
|
mocker,
|
2018-10-30 14:27:09 +00:00
|
|
|
|
mock_get_live_service,
|
2017-04-26 10:49:51 +01:00
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_get_users_by_service,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mock_s3_set_metadata,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
2019-02-04 14:08:11 +00:00
|
|
|
|
mock_get_jobs,
|
2017-04-26 10:49:51 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2020-03-12 17:19:57 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
|
|
|
|
|
return_value="addressline1, addressline2, postcode\na,b,sw1 1aa"
|
|
|
|
|
|
)
|
2018-05-03 13:35:59 +01:00
|
|
|
|
mocker.patch('app.main.views.send.set_metadata_on_csv_upload')
|
2017-05-04 09:30:55 +01:00
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=1)
|
|
|
|
|
|
|
2018-10-30 16:32:10 +00:00
|
|
|
|
page = client_request.get(
|
2017-04-26 10:49:51 +01:00
|
|
|
|
'main.check_messages',
|
2018-10-30 14:27:09 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-04-26 10:49:51 +01:00
|
|
|
|
upload_id=fake_uuid,
|
2018-03-29 17:01:35 +01:00
|
|
|
|
template_id=fake_uuid,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
)
|
2016-08-30 09:27:24 +01:00
|
|
|
|
|
2018-10-30 16:32:10 +00:00
|
|
|
|
assert 'name="scheduled_for"' not in page
|
|
|
|
|
|
assert normalize_spaces(
|
2019-12-20 13:51:15 +00:00
|
|
|
|
page.select_one('main [type=submit]').text
|
2018-10-30 16:32:10 +00:00
|
|
|
|
) == (
|
|
|
|
|
|
'Send 1 letter'
|
|
|
|
|
|
)
|
2016-08-30 09:27:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
|
|
['phone_number'] + (['07900900123'] * 1000)
|
|
|
|
|
|
))
|
|
|
|
|
|
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'
|
|
|
|
|
|
])
|
2020-03-16 17:00:34 +00:00
|
|
|
|
@pytest.mark.parametrize('contact_list_id', [
|
|
|
|
|
|
'', unchanging_fake_uuid,
|
|
|
|
|
|
])
|
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,
|
|
|
|
|
|
contact_list_id,
|
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,
|
|
|
|
|
|
'contact_list_id': contact_list_id,
|
|
|
|
|
|
},
|
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,
|
2020-03-16 17:00:34 +00:00
|
|
|
|
contact_list_id=str(contact_list_id),
|
2016-08-25 13:27:24 +01:00
|
|
|
|
)
|
2016-03-03 15:26:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-01-20 16:20:37 +00:00
|
|
|
|
def test_can_start_letters_job(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
2016-11-08 13:10:38 +00:00
|
|
|
|
mock_create_job,
|
2017-02-14 14:06:02 +00:00
|
|
|
|
service_one,
|
2016-11-08 13:10:38 +00:00
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
2021-12-30 16:13:49 +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': 123,
|
|
|
|
|
|
'valid': True
|
|
|
|
|
|
}
|
2016-11-08 13:10:38 +00:00
|
|
|
|
}
|
2018-03-13 16:29:20 +00:00
|
|
|
|
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
2021-12-31 12:16:12 +00:00
|
|
|
|
response = client_request.post_response(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
'main.start_job',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
_data={},
|
|
|
|
|
|
_expected_status=302,
|
2016-11-08 13:10:38 +00:00
|
|
|
|
)
|
2017-07-13 11:28:37 +01:00
|
|
|
|
assert 'just_sent=yes' in response.location
|
2016-11-08 13:10:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
2018-10-15 14:02:13 +01:00
|
|
|
|
@pytest.mark.parametrize('filetype, extra_args, expected_values, expected_page', [
|
2017-12-06 22:04:58 +00:00
|
|
|
|
(
|
2018-10-15 14:02:13 +01:00
|
|
|
|
'png',
|
2017-12-06 22:04:58 +00:00
|
|
|
|
{},
|
|
|
|
|
|
{'postcode': 'abc123', 'addressline1': '123 street'},
|
2018-10-15 14:02:13 +01:00
|
|
|
|
1
|
2017-12-06 22:04:58 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2018-10-15 14:02:13 +01:00
|
|
|
|
'pdf',
|
|
|
|
|
|
{},
|
|
|
|
|
|
{'postcode': 'abc123', 'addressline1': '123 street'},
|
|
|
|
|
|
None
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'png',
|
2018-01-15 11:35:45 +00:00
|
|
|
|
{'row_index': 2},
|
2017-12-06 22:04:58 +00:00
|
|
|
|
{'postcode': 'abc123', 'addressline1': '123 street'},
|
2018-10-15 14:02:13 +01:00
|
|
|
|
1
|
2017-12-06 22:04:58 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2018-10-15 14:02:13 +01:00
|
|
|
|
'png',
|
2018-01-15 11:35:45 +00:00
|
|
|
|
{'row_index': 3},
|
2017-12-06 22:04:58 +00:00
|
|
|
|
{'postcode': 'cba321', 'addressline1': '321 avenue'},
|
2018-10-15 14:02:13 +01:00
|
|
|
|
1
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'png',
|
|
|
|
|
|
{'row_index': 3, 'page': 2},
|
|
|
|
|
|
{'postcode': 'cba321', 'addressline1': '321 avenue'},
|
|
|
|
|
|
'2'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# pdf expected page is always None
|
|
|
|
|
|
'pdf',
|
|
|
|
|
|
{'row_index': 3, 'page': 2},
|
|
|
|
|
|
{'postcode': 'cba321', 'addressline1': '321 avenue'},
|
|
|
|
|
|
None
|
2017-12-06 22:04:58 +00:00
|
|
|
|
),
|
|
|
|
|
|
])
|
2016-12-20 14:38:34 +00:00
|
|
|
|
def test_should_show_preview_letter_message(
|
2017-04-10 18:12:00 +01:00
|
|
|
|
filetype,
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
2016-12-20 14:38:34 +00:00
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
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-14 14:06:02 +00:00
|
|
|
|
service_one,
|
2016-12-20 14:38:34 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
2017-12-06 22:04:58 +00:00
|
|
|
|
extra_args,
|
|
|
|
|
|
expected_values,
|
2018-10-15 14:02:13 +01:00
|
|
|
|
expected_page
|
2016-12-20 14:38:34 +00:00
|
|
|
|
):
|
2017-06-23 13:35:08 +01:00
|
|
|
|
service_one['permissions'] = ['letter']
|
2017-02-14 14:06:02 +00:00
|
|
|
|
mocker.patch('app.service_api_client.get_service', return_value={"data": service_one})
|
2017-05-04 09:30:55 +01:00
|
|
|
|
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=1)
|
2016-12-20 14:38:34 +00:00
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
|
|
|
|
|
return_value='\n'.join(
|
|
|
|
|
|
['address line 1, postcode'] +
|
2017-12-06 22:04:58 +00:00
|
|
|
|
['123 street, abc123'] +
|
|
|
|
|
|
['321 avenue, cba321']
|
2016-12-20 14:38:34 +00:00
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_csv_metadata',
|
|
|
|
|
|
return_value={'original_file_name': f'example.{filetype}'},
|
|
|
|
|
|
)
|
2017-04-10 18:12:00 +01:00
|
|
|
|
mocked_preview = mocker.patch(
|
|
|
|
|
|
'app.main.views.send.TemplatePreview.from_utils_template',
|
|
|
|
|
|
return_value='foo'
|
|
|
|
|
|
)
|
2016-12-20 14:38:34 +00:00
|
|
|
|
|
2017-02-14 14:06:02 +00:00
|
|
|
|
service_id = service_one['id']
|
2016-12-20 14:38:34 +00:00
|
|
|
|
template_id = fake_uuid
|
2021-12-30 16:13:49 +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
|
|
|
|
|
|
}
|
2016-12-20 14:38:34 +00:00
|
|
|
|
}
|
2018-03-13 16:29:20 +00:00
|
|
|
|
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
2021-12-31 12:16:12 +00:00
|
|
|
|
response = client_request.get_response(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
'no_cookie.check_messages_preview',
|
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
filetype=filetype,
|
|
|
|
|
|
**extra_args
|
2017-02-14 14:06:02 +00:00
|
|
|
|
)
|
2016-12-20 14:38:34 +00:00
|
|
|
|
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_letter_template.assert_called_with(service_id, template_id, None)
|
2017-04-10 18:12:00 +01:00
|
|
|
|
|
|
|
|
|
|
assert response.get_data(as_text=True) == 'foo'
|
|
|
|
|
|
assert mocked_preview.call_args[0][0].id == template_id
|
|
|
|
|
|
assert type(mocked_preview.call_args[0][0]) == LetterPreviewTemplate
|
|
|
|
|
|
assert mocked_preview.call_args[0][1] == filetype
|
2017-12-06 22:04:58 +00:00
|
|
|
|
assert mocked_preview.call_args[0][0].values == expected_values
|
2018-10-15 14:02:13 +01:00
|
|
|
|
assert mocked_preview.call_args[1] == {'page': expected_page}
|
2016-12-20 14:38:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-04-12 12:12:11 +01:00
|
|
|
|
def test_dont_show_preview_letter_templates_for_bad_filetype(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2017-04-12 12:12:11 +01:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request.get_response(
|
|
|
|
|
|
'no_cookie.check_messages_preview',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
filetype='blah',
|
|
|
|
|
|
_expected_status=404,
|
2017-04-12 12:12:11 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert mock_get_service_template.called is False
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
2017-07-03 17:21:44 +01:00
|
|
|
|
session['recipient'] = '07700900001'
|
|
|
|
|
|
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')
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-01-08 09:10:04 +00:00
|
|
|
|
'letter',
|
|
|
|
|
|
False,
|
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
|
|
|
|
),
|
|
|
|
|
|
(
|
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
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=5,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
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 (
|
2020-02-17 15:36:46 +00:00
|
|
|
|
page.find_all('a', {'class': 'govuk-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=(
|
|
|
|
|
|
'phone number,\n07900900321' # Not in team
|
|
|
|
|
|
))
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-07 10:47:00 +00:00
|
|
|
|
@pytest.mark.parametrize('restricted, error_should_be_shown', [
|
|
|
|
|
|
(True, True),
|
|
|
|
|
|
(False, False),
|
2017-08-08 10:01:44 +01:00
|
|
|
|
])
|
2017-08-08 10:31:09 +01:00
|
|
|
|
@pytest.mark.parametrize('number_of_rows, expected_error_message', [
|
2019-09-13 09:35:05 +01:00
|
|
|
|
(1, 'You cannot send this letter'),
|
|
|
|
|
|
(11, 'You cannot send these letters'), # Less than trial mode limit
|
|
|
|
|
|
(111, 'You cannot send these letters'), # More than trial mode limit
|
2017-08-08 10:31:09 +01:00
|
|
|
|
])
|
2017-08-08 10:01:44 +01:00
|
|
|
|
def test_check_messages_shows_trial_mode_error_for_letters(
|
|
|
|
|
|
client_request,
|
2020-01-07 10:47:00 +00:00
|
|
|
|
service_one,
|
2017-08-08 10:01:44 +01:00
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
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,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2018-04-27 16:05:04 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2018-03-13 16:29:20 +00:00
|
|
|
|
fake_uuid,
|
2017-08-08 10:01:44 +01:00
|
|
|
|
mocker,
|
2020-01-07 10:47:00 +00:00
|
|
|
|
restricted,
|
2017-08-08 10:01:44 +01:00
|
|
|
|
error_should_be_shown,
|
2017-08-08 10:31:09 +01:00
|
|
|
|
number_of_rows,
|
|
|
|
|
|
expected_error_message,
|
2017-08-08 10:01:44 +01:00
|
|
|
|
):
|
2020-01-07 10:47:00 +00:00
|
|
|
|
service_one['restricted'] = restricted
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_service', return_value={'data': service_one})
|
2017-08-08 10:01:44 +01:00
|
|
|
|
|
2017-08-08 10:31:09 +01:00
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value='\n'.join(
|
|
|
|
|
|
['address_line_1,address_line_2,postcode,'] +
|
|
|
|
|
|
['First Last, 123 Street, SW1 1AA'] * number_of_rows
|
|
|
|
|
|
))
|
2018-10-01 16:03:06 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=3,
|
|
|
|
|
|
)
|
2017-08-08 10:01:44 +01:00
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'template_id': '',
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-08-08 10:01:44 +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-08-08 10:01:44 +01:00
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
error = page.select('.banner-dangerous')
|
|
|
|
|
|
|
|
|
|
|
|
if error_should_be_shown:
|
|
|
|
|
|
assert normalize_spaces(error[0].text) == (
|
2017-08-08 10:31:09 +01:00
|
|
|
|
'{} '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'In trial mode you can only preview how your letters will look'
|
2017-08-08 10:31:09 +01:00
|
|
|
|
).format(expected_error_message)
|
2017-08-08 10:01:44 +01:00
|
|
|
|
else:
|
|
|
|
|
|
assert not error
|
|
|
|
|
|
|
2018-10-01 16:03:06 +01:00
|
|
|
|
assert len(page.select('.letter img')) == 3
|
|
|
|
|
|
|
2018-05-21 10:06:16 +01:00
|
|
|
|
if number_of_rows > 1:
|
|
|
|
|
|
assert page.select_one('.table-field-index a').text == '3'
|
|
|
|
|
|
|
2017-08-08 10:01:44 +01:00
|
|
|
|
|
2019-10-01 15:34:46 +01:00
|
|
|
|
@pytest.mark.parametrize('number_of_rows, expected_error_message', [
|
|
|
|
|
|
(1, 'This letter is'),
|
|
|
|
|
|
(11, 'These letters are'), # TODO: Pluralise too many pages error message for multiple letters
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_check_messages_does_not_allow_to_send_letter_longer_than_10_pages(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_get_jobs,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2019-10-01 15:34:46 +01:00
|
|
|
|
mock_s3_set_metadata,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
number_of_rows,
|
|
|
|
|
|
expected_error_message,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value='\n'.join(
|
|
|
|
|
|
['address_line_1,address_line_2,postcode,'] +
|
|
|
|
|
|
['First Last, 123 Street, SW1 1AA'] * number_of_rows
|
|
|
|
|
|
))
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=11,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'template_id': '',
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
2019-10-25 16:53:31 +01:00
|
|
|
|
assert page.find('h1', {"data-error-type": "letter-too-long"})
|
2019-10-01 15:34:46 +01:00
|
|
|
|
|
|
|
|
|
|
assert len(page.select('.letter img')) == 10 # if letter longer than 10 pages, only 10 first pages are displayed
|
2019-12-20 13:51:15 +00:00
|
|
|
|
assert not page.select('main [type=submit]')
|
2019-10-01 15:34:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-09-14 12:21:40 +01:00
|
|
|
|
def test_check_messages_shows_data_errors_before_trial_mode_errors_for_letters(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
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,
|
2018-05-03 13:35:59 +01:00
|
|
|
|
fake_uuid,
|
2020-10-21 13:07:59 +01:00
|
|
|
|
mock_s3_get_metadata,
|
2017-09-14 12:21:40 +01:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value='\n'.join(
|
|
|
|
|
|
['address_line_1,address_line_2,postcode,'] +
|
2020-03-12 17:19:57 +00:00
|
|
|
|
[' , ,SW1 1AA'] +
|
|
|
|
|
|
[' , ,SW1 1AA']
|
2017-09-14 12:21:40 +01:00
|
|
|
|
))
|
|
|
|
|
|
|
2018-10-01 16:03:06 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=5,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2017-09-14 12:21:40 +01:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'template_id': '',
|
2020-10-21 13:07:59 +01:00
|
|
|
|
'original_file_name': 'example.csv',
|
2018-03-13 16:29:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-09-14 12:21:40 +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-09-14 12:21:40 +01:00
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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 fix 2 addresses.'
|
2017-09-14 12:21:40 +01:00
|
|
|
|
)
|
2018-05-21 10:06:16 +01:00
|
|
|
|
assert not page.select('.table-field-index a')
|
2017-09-14 12:21:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-02-04 14:08:11 +00:00
|
|
|
|
@pytest.mark.parametrize('uploaded_file_name', (
|
|
|
|
|
|
pytest.param('applicants.ods'), # normal job
|
|
|
|
|
|
pytest.param('thisisatest.csv', marks=pytest.mark.xfail), # different template version
|
|
|
|
|
|
pytest.param('send_me_later.csv'), # should look at scheduled job
|
|
|
|
|
|
pytest.param('full_of_regret.csv', marks=pytest.mark.xfail), # job is cancelled
|
|
|
|
|
|
))
|
|
|
|
|
|
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=(
|
|
|
|
|
|
'phone number,\n07900900321'
|
|
|
|
|
|
))
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-03 14:08:25 +01:00
|
|
|
|
def test_check_messages_column_error_doesnt_show_optional_columns(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
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']
|
|
|
|
|
|
))
|
|
|
|
|
|
|
2018-10-01 16:03:06 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=5,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2017-10-03 14:08:25 +01:00
|
|
|
|
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 '
|
2020-04-19 22:46:13 +01:00
|
|
|
|
'Your file needs at least 3 address columns, for example ‘address line 1’, '
|
|
|
|
|
|
'‘address line 2’ and ‘address line 3’. '
|
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=(
|
|
|
|
|
|
'phone number,\n07900900321'
|
|
|
|
|
|
))
|
|
|
|
|
|
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',
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-15 13:51:48 +01:00
|
|
|
|
def test_check_messages_does_not_add_sender_id_in_session_to_metadata_for_letter_template(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
mock_s3_get_metadata,
|
|
|
|
|
|
mock_s3_set_metadata,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value="""
|
|
|
|
|
|
address_line_1,address_line_2,postcode,
|
|
|
|
|
|
First Last, 123 Street, SW1 1AA
|
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=5,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
valid=True,
|
|
|
|
|
|
original_file_name='example.csv',
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-30 14:27:09 +00:00
|
|
|
|
@pytest.mark.parametrize('extra_args', (
|
|
|
|
|
|
{},
|
|
|
|
|
|
{'from_test': True},
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_letters_from_csv_files_dont_have_download_link(
|
2017-08-25 14:17:23 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_has_permissions,
|
2018-03-13 16:29:20 +00:00
|
|
|
|
fake_uuid,
|
2017-08-25 14:17:23 +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,
|
2018-04-27 16:05:04 +01:00
|
|
|
|
mock_s3_set_metadata,
|
2018-10-30 14:27:09 +00:00
|
|
|
|
extra_args,
|
2017-08-25 14:17:23 +01:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value="""
|
|
|
|
|
|
address_line_1,address_line_2,postcode,
|
|
|
|
|
|
First Last, 123 Street, SW1 1AA
|
|
|
|
|
|
""")
|
|
|
|
|
|
|
2018-10-01 16:03:06 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=5,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2017-08-25 14:17:23 +01:00
|
|
|
|
with client_request.session_transaction() as session:
|
2018-03-13 16:29:20 +00:00
|
|
|
|
session['file_uploads'] = {
|
|
|
|
|
|
fake_uuid: {
|
|
|
|
|
|
'template_id': '',
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-08-25 14:17:23 +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,
|
2018-10-30 14:27:09 +00:00
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
**extra_args
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select_one('.banner-dangerous').text
|
|
|
|
|
|
) == normalize_spaces(
|
2019-09-13 09:35:05 +01:00
|
|
|
|
'You cannot send this letter '
|
2020-08-18 11:55:22 +01:00
|
|
|
|
'In trial mode you can only preview how your letters will look'
|
2018-10-30 14:27:09 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert len(page.select('.letter img')) == 5
|
|
|
|
|
|
assert not page.select('a[download]')
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-07 10:47:00 +00:00
|
|
|
|
@pytest.mark.parametrize('restricted', [True, False])
|
2018-10-30 14:27:09 +00:00
|
|
|
|
def test_one_off_letters_have_download_link(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
2020-01-07 10:47:00 +00:00
|
|
|
|
restricted,
|
|
|
|
|
|
service_one,
|
2018-10-30 14:27:09 +00:00
|
|
|
|
):
|
2020-01-07 10:47:00 +00:00
|
|
|
|
service_one['restricted'] = restricted
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_service', return_value={'data': service_one})
|
2018-10-30 14:27:09 +00:00
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=5,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {
|
|
|
|
|
|
'address_line_1': 'First Last',
|
|
|
|
|
|
'address_line_2': '123 Street',
|
|
|
|
|
|
'postcode': 'SW1 1AA',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_notification',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2017-08-25 14:17:23 +01:00
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2018-10-01 16:03:06 +01:00
|
|
|
|
assert len(page.select('.letter img')) == 5
|
2018-10-30 14:27:09 +00:00
|
|
|
|
|
|
|
|
|
|
assert page.select_one('a[download]')['href'] == url_for(
|
2019-11-29 11:40:49 +00:00
|
|
|
|
'no_cookie.check_notification_preview',
|
2018-10-30 14:27:09 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
filetype='pdf',
|
|
|
|
|
|
)
|
2018-11-22 12:17:11 +00:00
|
|
|
|
assert page.select_one('a[download]').text == 'Download as a PDF'
|
2017-08-25 14:17:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-10-30 16:32:10 +00:00
|
|
|
|
def test_send_one_off_letter_errors_in_trial_mode(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_s3_set_metadata,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=5,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {
|
|
|
|
|
|
'address_line_1': 'First Last',
|
|
|
|
|
|
'address_line_2': '123 Street',
|
|
|
|
|
|
'postcode': 'SW1 1AA',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_notification',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select('.banner-dangerous')) == normalize_spaces(
|
2019-09-13 09:35:05 +01:00
|
|
|
|
'You cannot send this letter '
|
2018-10-30 16:32:10 +00:00
|
|
|
|
'In trial mode you can only preview how your letters will look'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert len(page.select('.letter img')) == 5
|
|
|
|
|
|
|
2019-12-20 13:51:15 +00:00
|
|
|
|
assert not page.select('main [type=submit]')
|
2019-04-29 11:44:05 +01:00
|
|
|
|
assert page.select_one('.govuk-back-link').text == 'Back'
|
2018-11-22 12:17:11 +00:00
|
|
|
|
assert page.select_one('a[download]').text == 'Download as a PDF'
|
2018-10-30 16:32:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-10-01 14:31:36 +01:00
|
|
|
|
def test_send_one_off_letter_errors_if_letter_longer_than_10_pages(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_live_service,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_job_doesnt_exist,
|
|
|
|
|
|
mock_s3_set_metadata,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.get_page_count_for_letter',
|
|
|
|
|
|
return_value=11,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = {
|
|
|
|
|
|
'address_line_1': 'First Last',
|
|
|
|
|
|
'address_line_2': '123 Street',
|
|
|
|
|
|
'postcode': 'SW1 1AA',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_notification',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2019-10-25 16:53:31 +01:00
|
|
|
|
assert page.find('h1', {"data-error-type": "letter-too-long"})
|
2019-10-01 14:31:36 +01:00
|
|
|
|
assert len(page.select('.letter img')) == 10
|
|
|
|
|
|
|
2019-12-20 13:51:15 +00:00
|
|
|
|
assert not page.select('main [type=submit]')
|
2019-10-01 14:31:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
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', [
|
|
|
|
|
|
{},
|
|
|
|
|
|
{'recipient': '07700900001'},
|
|
|
|
|
|
{'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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
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:
|
|
|
|
|
|
session['recipient'] = '07700900001'
|
|
|
|
|
|
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 (
|
2020-02-17 15:36:46 +00:00
|
|
|
|
page.find_all('a', {'class': 'govuk-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'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-15 15:42:25 +01:00
|
|
|
|
def test_check_notification_shows_back_link(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_template_preview
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['restricted'] = False
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': template_json(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
name="Awkward letter",
|
|
|
|
|
|
type_="letter",
|
|
|
|
|
|
subject="We need to talk about ((thing))",
|
2021-03-08 15:36:23 +00:00
|
|
|
|
content="Hello ((address line 3))",
|
2020-04-15 15:42:25 +01:00
|
|
|
|
)},
|
|
|
|
|
|
)
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = 'foo'
|
|
|
|
|
|
session['placeholders'] = {
|
|
|
|
|
|
'address_line_1': 'foo',
|
|
|
|
|
|
'address_line_2': 'bar',
|
|
|
|
|
|
'address_line_3': '',
|
|
|
|
|
|
'address_line_4': '',
|
|
|
|
|
|
'address_line_5': '',
|
|
|
|
|
|
'address_line_6': '',
|
|
|
|
|
|
'address_line_7': 'SW1A 1AA',
|
|
|
|
|
|
'postcode': 'SW1A 1AA',
|
|
|
|
|
|
'thing': 'a thing',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.check_notification',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.h1.text.strip() == 'Preview of ‘Awkward letter’'
|
|
|
|
|
|
back_link = page.find_all('a', {'class': 'govuk-back-link'})[0]['href']
|
|
|
|
|
|
assert back_link == url_for(
|
|
|
|
|
|
'main.send_one_off_step',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=7,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
previous_page = client_request.get_url(back_link)
|
|
|
|
|
|
assert normalize_spaces(previous_page.select_one('label').text) == 'thing'
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-30 14:24:50 +00:00
|
|
|
|
@pytest.mark.parametrize('template, recipient, placeholders, expected_personalisation', (
|
|
|
|
|
|
(
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
'07700900001',
|
|
|
|
|
|
{'a': 'b'},
|
|
|
|
|
|
{'a': 'b'},
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
'test@example.com',
|
|
|
|
|
|
{},
|
|
|
|
|
|
{},
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
'foo',
|
|
|
|
|
|
{},
|
|
|
|
|
|
{},
|
|
|
|
|
|
),
|
|
|
|
|
|
))
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-07 12:59:34 +01:00
|
|
|
|
@pytest.mark.parametrize('placeholders', (
|
|
|
|
|
|
{'address line 1': 'Foo'},
|
|
|
|
|
|
{'ADDRESSLINE_1': 'Foo'},
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_send_notification_submits_data_for_letter(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_send_notification,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
placeholders,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = None
|
|
|
|
|
|
session['placeholders'] = placeholders
|
|
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.send_notification',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
)
|
|
|
|
|
|
assert mock_send_notification.call_args[1]['recipient'] == 'Foo'
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
session['recipient'] = '07700900001'
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
with client_request.session_transaction() as session:
|
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,
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
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:
|
2017-06-26 17:09:51 +01:00
|
|
|
|
session['recipient'] = '07700900001'
|
|
|
|
|
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
**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:
|
|
|
|
|
|
session['recipient'] = '07700900001'
|
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,
|
2020-03-16 14:57:36 +00:00
|
|
|
|
mock_get_no_contact_lists,
|
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,
|
2020-03-16 14:57:36 +00:00
|
|
|
|
mock_get_no_contact_lists,
|
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
|
|
|
|
|
|
7700900986,foo,bar
|
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['recipient'] = '7700900986'
|
|
|
|
|
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-03-13 14:38:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-03-16 09:41:42 +00:00
|
|
|
|
@pytest.mark.parametrize((
|
|
|
|
|
|
'template_type, '
|
|
|
|
|
|
'expected_list_id, '
|
2020-05-12 17:52:13 +01:00
|
|
|
|
'expected_filenames, '
|
2020-03-16 09:41:42 +00:00
|
|
|
|
'expected_time, '
|
|
|
|
|
|
'expected_count'
|
|
|
|
|
|
), (
|
|
|
|
|
|
(
|
|
|
|
|
|
'email',
|
|
|
|
|
|
'6ce466d0-fd6a-11e5-82f5-e0accb9d11a6',
|
2020-05-12 17:52:13 +01:00
|
|
|
|
['EmergencyContactList.xls'],
|
2020-03-16 09:41:42 +00:00
|
|
|
|
'Uploaded today at 10:59am',
|
|
|
|
|
|
'100 email addresses',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms',
|
|
|
|
|
|
'd7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad',
|
2020-05-12 17:52:13 +01:00
|
|
|
|
['phone number list.csv', 'UnusedList.tsv'],
|
2020-03-16 09:41:42 +00:00
|
|
|
|
'Uploaded today at 1:00pm',
|
|
|
|
|
|
'123 phone numbers',
|
|
|
|
|
|
),
|
|
|
|
|
|
))
|
2021-09-14 13:28:27 +01:00
|
|
|
|
@freeze_time('2020-06-13 13:00')
|
2020-03-13 17:51:22 +00:00
|
|
|
|
def test_choose_from_contact_list(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_contact_lists,
|
|
|
|
|
|
fake_uuid,
|
2020-03-16 09:41:42 +00:00
|
|
|
|
template_type,
|
|
|
|
|
|
expected_list_id,
|
2020-05-12 17:52:13 +01:00
|
|
|
|
expected_filenames,
|
2020-03-16 09:41:42 +00:00
|
|
|
|
expected_time,
|
|
|
|
|
|
expected_count,
|
2020-03-13 17:51:22 +00:00
|
|
|
|
):
|
2020-03-16 09:41:42 +00:00
|
|
|
|
template = create_template(template_type=template_type)
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': template},
|
|
|
|
|
|
)
|
2020-03-13 17:51:22 +00:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_from_contact_list',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
2020-05-12 17:52:13 +01:00
|
|
|
|
assert [
|
|
|
|
|
|
normalize_spaces(filename.text)
|
|
|
|
|
|
for filename in page.select('.file-list-filename-large')
|
|
|
|
|
|
] == expected_filenames
|
|
|
|
|
|
|
2020-03-13 17:51:22 +00:00
|
|
|
|
assert page.select_one('a.file-list-filename-large')['href'] == url_for(
|
|
|
|
|
|
'main.send_from_contact_list',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2020-03-16 09:41:42 +00:00
|
|
|
|
template_id=template['id'],
|
|
|
|
|
|
contact_list_id=expected_list_id,
|
2020-03-13 17:51:22 +00:00
|
|
|
|
)
|
2020-03-16 14:14:29 +00:00
|
|
|
|
assert normalize_spaces(page.select_one('.file-list-hint-large').text) == (
|
2020-03-16 09:41:42 +00:00
|
|
|
|
expected_time
|
2020-03-13 17:51:22 +00:00
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.big-number-smallest').text) == (
|
2020-03-16 09:41:42 +00:00
|
|
|
|
expected_count
|
2020-03-13 17:51:22 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-16 10:34:05 +00:00
|
|
|
|
def test_choose_from_contact_list_with_personalised_template(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_contact_lists,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
template = create_template(
|
|
|
|
|
|
content="Hey ((name)) ((thing)) is happening"
|
|
|
|
|
|
)
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': template},
|
|
|
|
|
|
)
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_from_contact_list',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
normalize_spaces(p.text) for p in page.select('main p')
|
|
|
|
|
|
] == [
|
2020-12-31 14:03:54 +00:00
|
|
|
|
'You cannot use an emergency contact list with this template because '
|
2020-03-16 10:34:05 +00:00
|
|
|
|
'it is personalised with ((name)) and ((thing)).',
|
2020-12-31 14:03:54 +00:00
|
|
|
|
'Emergency contact lists can only include email addresses or phone numbers.',
|
2020-03-16 10:34:05 +00:00
|
|
|
|
]
|
|
|
|
|
|
assert not page.select('table')
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-16 09:41:42 +00:00
|
|
|
|
def test_choose_from_contact_list_with_no_lists(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.models.contact_list.ContactLists.client_method',
|
|
|
|
|
|
return_value=[],
|
|
|
|
|
|
)
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_from_contact_list',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
normalize_spaces(p.text) for p in page.select('main p')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
'You have not saved any lists of phone numbers yet.',
|
2020-12-31 14:03:54 +00:00
|
|
|
|
'To upload and save an emergency contact list, go to the uploads page.',
|
2020-03-16 09:41:42 +00:00
|
|
|
|
]
|
|
|
|
|
|
assert page.select_one('main p a')['href'] == url_for(
|
|
|
|
|
|
'main.uploads',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert not page.select('table')
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-13 14:38:43 +00:00
|
|
|
|
def test_send_from_contact_list(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
2020-03-17 11:30:27 +00:00
|
|
|
|
mock_get_contact_list,
|
2020-03-13 14:38:43 +00:00
|
|
|
|
):
|
|
|
|
|
|
new_uuid = uuid.uuid4()
|
|
|
|
|
|
mock_download = mocker.patch('app.models.contact_list.s3download', return_value='contents')
|
|
|
|
|
|
mock_get_metadata = mocker.patch('app.models.contact_list.get_csv_metadata', return_value={
|
|
|
|
|
|
'example_key': 'example value',
|
|
|
|
|
|
})
|
|
|
|
|
|
mock_upload = mocker.patch('app.models.contact_list.s3upload', return_value=new_uuid)
|
|
|
|
|
|
mock_set_metadata = mocker.patch('app.models.contact_list.set_metadata_on_csv_upload')
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.send_from_contact_list',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
contact_list_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
upload_id=new_uuid,
|
2020-03-16 17:00:34 +00:00
|
|
|
|
contact_list_id=fake_uuid,
|
2020-03-13 14:38:43 +00:00
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
mock_download.assert_called_once_with(
|
|
|
|
|
|
SERVICE_ONE_ID, fake_uuid, bucket='test-contact-list'
|
|
|
|
|
|
)
|
|
|
|
|
|
mock_get_metadata.assert_called_once_with(
|
|
|
|
|
|
SERVICE_ONE_ID, fake_uuid, bucket='test-contact-list'
|
|
|
|
|
|
)
|
|
|
|
|
|
mock_upload.assert_called_once_with(
|
2020-03-13 17:51:22 +00:00
|
|
|
|
SERVICE_ONE_ID, {'data': 'contents'}, ANY
|
2020-03-13 14:38:43 +00:00
|
|
|
|
)
|
|
|
|
|
|
mock_set_metadata.assert_called_once_with(
|
|
|
|
|
|
SERVICE_ONE_ID, new_uuid, example_key='example value'
|
|
|
|
|
|
)
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
assert session['recipient'] == 'test@user.gov.uk'
|
|
|
|
|
|
assert session['placeholders'] == {'email address': 'test@user.gov.uk'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
assert session['recipient'] == '07700 900762'
|
|
|
|
|
|
assert session['placeholders'] == {'phone number': '07700 900762'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_send_to_myself_404s_for_letter(
|
|
|
|
|
|
mocker, client_request, fake_uuid, mock_get_service_letter_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=404,
|
|
|
|
|
|
)
|