Don’t go back to address if address placeholder in letter

If you have an placeholder from the address block elsewhere in your
letter then you currently get redirected to the address block page
instead of being offered to fill that placeholder in. This commit
tightens up the check to only do this when the placeholder is in the
first 7 placeholders, which is where we store the address placeholders.
This commit is contained in:
Chris Hill-Scott
2020-04-09 14:33:47 +01:00
parent 713980a35e
commit 53918f8d9f
2 changed files with 66 additions and 6 deletions

View File

@@ -18,10 +18,7 @@ from notifications_python_client.errors import HTTPError
from notifications_utils import LETTER_MAX_PAGE_COUNT, SMS_CHAR_COUNT_LIMIT from notifications_utils import LETTER_MAX_PAGE_COUNT, SMS_CHAR_COUNT_LIMIT
from notifications_utils.columns import Columns from notifications_utils.columns import Columns
from notifications_utils.pdf import is_letter_too_long from notifications_utils.pdf import is_letter_too_long
from notifications_utils.postal_address import ( from notifications_utils.postal_address import PostalAddress
PostalAddress,
address_lines_1_to_6_and_postcode_keys,
)
from notifications_utils.recipients import ( from notifications_utils.recipients import (
RecipientCSV, RecipientCSV,
first_column_headings, first_column_headings,
@@ -476,8 +473,8 @@ def send_test_step(service_id, template_id, step_index):
)) ))
# if we're in a letter, we should show address block rather than "address line #" or "postcode" # if we're in a letter, we should show address block rather than "address line #" or "postcode"
if template.template_type == 'letter' and current_placeholder in ( if template.template_type == 'letter' and (
Columns.from_keys(address_lines_1_to_6_and_postcode_keys) step_index < len(first_column_headings['letter'])
): ):
return redirect(url_for('.send_one_off_letter_address', service_id=service_id, template_id=template_id)) return redirect(url_for('.send_one_off_letter_address', service_id=service_id, template_id=template_id))

View File

@@ -29,6 +29,7 @@ from xlrd.xldate import (
) )
from tests import ( from tests import (
template_json,
validate_route_permission, validate_route_permission,
validate_route_permission_with_client, validate_route_permission_with_client,
) )
@@ -2045,6 +2046,68 @@ def test_send_one_off_back_link_populates_address_textarea(
assert textarea.text == 'foo\nbar' assert textarea.text == 'foo\nbar'
@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,
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'] = {}
session['send_test_letter_page_count'] = None
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,
)
with client_request.session_transaction() as session:
assert normalize_spaces(page.select_one('form label').text) == placeholder
assert page.select_one('form input[type=text]')['value'] == (
session['placeholders'].get(placeholder, '')
)
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',
}
def test_send_test_sms_message_puts_submitted_data_in_session( def test_send_test_sms_message_puts_submitted_data_in_session(
client_request, client_request,
service_one, service_one,