mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-31 11:49:58 -04:00
Allow international addresses in spreadsheets
For services with permission, they can now put international addresses into their spreadsheets without getting a postcode error. This also means they can start using address line 7 instead of postcode, since it doesn’t make sense to put a country in a field called ‘postcode’. But this will be undocumented to start with, because we’re not giving any real users the permission. It does now mean that the number of possible placeholders (7 + postcode) is greater than the number of allowed placeholders (7), so we have to account for that in the one-off address flow where we’re populating the placeholders automatically. We’re sticking with 6 + postcode here for backwards compatibility.
This commit is contained in:
@@ -310,6 +310,37 @@ def test_example_spreadsheet(
|
||||
)
|
||||
|
||||
|
||||
def test_example_spreadsheet_for_letters(
|
||||
client_request,
|
||||
mocker,
|
||||
mock_get_service_letter_template_with_placeholders,
|
||||
fake_uuid,
|
||||
):
|
||||
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'),
|
||||
('address line 3', ''),
|
||||
('address line 4', ''),
|
||||
('address line 5', ''),
|
||||
('address line 6', ''),
|
||||
('postcode', 'XM4 5HQ'),
|
||||
('name', 'example'),
|
||||
('date', 'example'),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"filename, acceptable_file",
|
||||
list(zip(test_spreadsheet_files, repeat(True))) +
|
||||
@@ -576,6 +607,7 @@ def test_upload_csv_file_with_bad_postal_address_shows_check_page_with_errors(
|
||||
address line 1, address line 3, address line 6,
|
||||
Firstname Lastname, 123 Example St., SW1A 1AA
|
||||
Firstname Lastname, 123 Example St., SW!A !AA
|
||||
Firstname Lastname, 123 Example St., France
|
||||
, 123 Example St., SW!A !AA
|
||||
"1\n2\n3\n4\n5\n6\n7\n8"
|
||||
'''
|
||||
@@ -594,7 +626,7 @@ def test_upload_csv_file_with_bad_postal_address_shows_check_page_with_errors(
|
||||
page.select_one('.banner-dangerous').text
|
||||
) == (
|
||||
'There’s a problem with invalid.csv '
|
||||
'You need to fix 3 addresses. '
|
||||
'You need to fix 4 addresses. '
|
||||
'Skip to file contents'
|
||||
)
|
||||
assert [
|
||||
@@ -603,14 +635,69 @@ def test_upload_csv_file_with_bad_postal_address_shows_check_page_with_errors(
|
||||
'3 Last line of the address must be a real UK postcode',
|
||||
'Firstname Lastname 123 Example St. SW!A !AA',
|
||||
|
||||
'4 Address must be at least 3 lines long',
|
||||
'4 Last line of the address must be a real UK postcode',
|
||||
'Firstname Lastname 123 Example St. France',
|
||||
|
||||
'5 Address must be at least 3 lines long',
|
||||
'123 Example St. SW!A !AA',
|
||||
|
||||
'5 Address must be no more than 7 lines long',
|
||||
'6 Address must be no more than 7 lines long',
|
||||
'1 2 3 4 5 6 7 8',
|
||||
]
|
||||
|
||||
|
||||
def test_upload_csv_file_with_international_letters_permission_shows_appropriate_errors(
|
||||
logged_in_client,
|
||||
service_one,
|
||||
mocker,
|
||||
mock_get_service_letter_template,
|
||||
mock_s3_upload,
|
||||
mock_get_users_by_service,
|
||||
mock_get_service_statistics,
|
||||
mock_get_job_doesnt_exist,
|
||||
mock_get_jobs,
|
||||
fake_uuid,
|
||||
):
|
||||
service_one['permissions'] += ['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
|
||||
Firstname Lastname, 123 Example St., SW!A !AA
|
||||
Firstname Lastname, 123 Example St., Not France
|
||||
'''
|
||||
)
|
||||
|
||||
response = logged_in_client.post(
|
||||
url_for('main.send_messages', service_id=service_one['id'], template_id=fake_uuid),
|
||||
data={'file': (BytesIO(''.encode('utf-8')), 'invalid.csv')},
|
||||
content_type='multipart/form-data',
|
||||
follow_redirects=True
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert normalize_spaces(
|
||||
page.select_one('.banner-dangerous').text
|
||||
) == (
|
||||
'There’s a problem with invalid.csv '
|
||||
'You need to fix 2 addresses. '
|
||||
'Skip to file contents'
|
||||
)
|
||||
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',
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('file_contents, expected_error,', [
|
||||
(
|
||||
"""
|
||||
@@ -2475,20 +2562,45 @@ def test_send_one_off_letter_address_populates_address_fields_in_session(
|
||||
assert session['placeholders'] == expected_placeholders
|
||||
|
||||
|
||||
@pytest.mark.parametrize(['form_data', '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'),
|
||||
@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',
|
||||
),
|
||||
(
|
||||
'\n'.join(['a', 'b', 'c', 'd', 'e', 'f', 'g']),
|
||||
['international_letters'],
|
||||
'Last line of the address must be a UK postcode or another country',
|
||||
),
|
||||
])
|
||||
def test_send_one_off_letter_address_rejects_bad_addresses(
|
||||
client_request,
|
||||
service_one,
|
||||
fake_uuid,
|
||||
mock_get_service_letter_template,
|
||||
mock_template_preview,
|
||||
form_data,
|
||||
extra_permissions,
|
||||
expected_error_message
|
||||
):
|
||||
service_one['permissions'] += extra_permissions
|
||||
|
||||
with client_request.session_transaction() as session:
|
||||
session['recipient'] = None
|
||||
session['placeholders'] = {}
|
||||
@@ -2643,7 +2755,7 @@ def test_upload_csvfile_with_international_validates(
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert mock_recipients.call_args[1]['international_sms'] == should_allow_international
|
||||
assert mock_recipients.call_args[1]['allow_international_sms'] == should_allow_international
|
||||
|
||||
|
||||
def test_job_from_contact_list_knows_where_its_come_from(
|
||||
|
||||
@@ -878,6 +878,25 @@ def mock_get_service_letter_template(mocker):
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_service_letter_template_with_placeholders(mocker):
|
||||
def _get(service_id, template_id, version=None, postage='second'):
|
||||
template = template_json(
|
||||
service_id,
|
||||
template_id,
|
||||
name="Two week reminder",
|
||||
type_="letter",
|
||||
content="Hello ((name)) your thing is due on ((date))",
|
||||
subject="Subject",
|
||||
postage=postage,
|
||||
)
|
||||
return {'data': template}
|
||||
|
||||
return mocker.patch(
|
||||
'app.service_api_client.get_service_template', side_effect=_get
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_create_service_template(mocker, fake_uuid):
|
||||
def _create(name, type_, content, service, subject=None, process_type=None, parent_folder_id=None):
|
||||
|
||||
Reference in New Issue
Block a user