Strip the trailing comma on the first line of an address block.

This commit is contained in:
Rebecca Law
2020-01-08 11:22:14 +00:00
parent f7b3f9b06a
commit 9d1f92a752
5 changed files with 65 additions and 40 deletions

View File

@@ -199,7 +199,7 @@ def uploaded_letter_preview(service_id, file_id):
status = metadata.get('status')
error_shortcode = metadata.get('message')
invalid_pages = metadata.get('invalid_pages')
recipient = format_recipient(metadata.get('recipient'))
recipient = format_recipient(metadata.get('recipient', ''))
if invalid_pages:
invalid_pages = json.loads(invalid_pages)

View File

@@ -19,7 +19,7 @@
{% if item.status in ('pending-virus-check', 'virus-scan-failed') %}
<span class="file-list-filename loading-indicator">Checking</span>
{% else %}
<a class="file-list-filename" href="{{ url_for('.view_notification', service_id=current_service.id, notification_id=item.id) }}">{{ item.to.splitlines()[0].lstrip().rstrip(' ,') }}</a>
<a class="file-list-filename" href="{{ url_for('.view_notification', service_id=current_service.id, notification_id=item.id) }}">{{ item.to.splitlines()[0].lstrip().rstrip(' ,') if item.to else '' }}</a>
{% endif %}
<p class="file-list-hint">
{{ item.preview_of_content }}

View File

@@ -276,7 +276,8 @@ def test_letters_with_status_virus_scan_failed_shows_a_failure_description(
mocker,
active_user_with_permissions,
is_precompiled_letter=True,
noti_status='virus-scan-failed'
noti_status='virus-scan-failed',
client_reference='client reference'
)
page = client_request.get(
'main.view_notifications',
@@ -294,6 +295,7 @@ def test_letters_with_status_virus_scan_failed_shows_a_failure_description(
])
def test_should_not_show_preview_link_for_precompiled_letters_in_virus_states(
mocker,
active_user_with_permissions,
client_request,
service_one,
mock_get_service_statistics,
@@ -301,9 +303,13 @@ def test_should_not_show_preview_link_for_precompiled_letters_in_virus_states(
mock_get_no_api_keys,
letter_status,
):
notifications = create_notifications(template_type='letter', status=letter_status)
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
mock_get_notifications(
mocker,
active_user_with_permissions,
is_precompiled_letter=True,
noti_status=letter_status,
client_reference='ref'
)
page = client_request.get(
'main.view_notifications',
service_id=service_one['id'],
@@ -414,12 +420,43 @@ def test_search_recipient_form(
assert field['value'] == expected_search_box_contents
@pytest.mark.parametrize('message_type, expected_search_box_label', [
(None, 'Search by email address, phone number or reference'),
('sms', 'Search by phone number or reference'),
('email', 'Search by email address or reference'),
@pytest.mark.parametrize((
'message_type,'
'api_keys_mock,'
'expected_search_box_label,'
), [
(
None,
mock_get_no_api_keys,
'Search by email address or phone number',
),
(
None,
mock_get_api_keys,
'Search by email address, phone number or reference',
),
(
'sms',
mock_get_no_api_keys,
'Search by phone number',
),
(
'sms',
mock_get_api_keys,
'Search by phone number or reference',
),
(
'email',
mock_get_no_api_keys,
'Search by email address',
),
(
'email',
mock_get_api_keys,
'Search by email address or reference',
),
])
def test_api_users_are_told_they_can_search_by_reference_when_service_has_api_keys(
def test_api_users_are_told_they_can_search_by_reference(
client_request,
mocker,
fake_uuid,
@@ -428,32 +465,9 @@ def test_api_users_are_told_they_can_search_by_reference_when_service_has_api_ke
mock_get_service_data_retention,
message_type,
expected_search_box_label,
mock_get_api_keys,
):
page = client_request.get(
'main.view_notifications',
service_id=SERVICE_ONE_ID,
message_type=message_type,
)
assert page.select_one('label[for=to]').text.strip() == expected_search_box_label
@pytest.mark.parametrize('message_type, expected_search_box_label', [
(None, 'Search by email address or phone number'),
('sms', 'Search by phone number'),
('email', 'Search by email address'),
])
def test_api_users_are_not_told_they_can_search_by_reference_when_service_has_no_api_keys(
client_request,
mocker,
fake_uuid,
mock_get_notifications,
mock_get_service_statistics,
mock_get_service_data_retention,
message_type,
expected_search_box_label,
mock_get_no_api_keys,
api_keys_mock,
):
api_keys_mock(mocker, fake_uuid)
page = client_request.get(
'main.view_notifications',
service_id=SERVICE_ONE_ID,
@@ -697,11 +711,11 @@ def test_sending_status_hint_displays_correctly_on_notifications_page(
assert bool(page.select('.align-with-message-body')) is single_line
@pytest.mark.parametrize("is_precompiled_letter,expected_hint", [
(True, "Provided as PDF"),
(False, "template subject")
@pytest.mark.parametrize("is_precompiled_letter,expected_address,expected_hint", [
(True, "Full Name,\nFirst address line\npostcode", "ref"),
(False, "Full Name,\nFirst address line\npostcode", "template subject")
])
def test_should_expected_hint_for_letters(
def test_should_show_address_and_hint_for_letters(
client_request,
service_one,
mock_get_service_statistics,
@@ -724,4 +738,5 @@ def test_should_expected_hint_for_letters(
message_type='letter',
)
assert page.select_one('a.file-list-filename').text == 'Full Name'
assert page.find('p', {'class': 'file-list-hint'}).text.strip() == expected_hint

View File

@@ -535,6 +535,7 @@ def test_send_uploaded_letter_when_metadata_states_pdf_is_invalid(mocker, servic
('The Queen,\nBuckingham Palace,\r\nSW1 1AA', 'The Queen, Buckingham Palace, SW1 1AA'),
('The Queen ,,\nBuckingham Palace,\rSW1 1AA,', 'The Queen, Buckingham Palace, SW1 1AA'),
(' The Queen\n Buckingham Palace\n SW1 1AA', 'The Queen, Buckingham Palace, SW1 1AA'),
('', ''),
])
def test_format_recipient(original_address, expected_address):
assert format_recipient(urllib.parse.quote(original_address)) == expected_address

View File

@@ -1791,6 +1791,7 @@ def mock_get_notifications(
return notification_json(
service_id,
template=template,
to=to,
rows=rows,
job=job,
with_links=True if count_pages is None else count_pages,
@@ -2879,6 +2880,14 @@ def mock_create_service_inbound_api(mocker):
return mocker.patch('app.service_api_client.create_service_inbound_api', side_effect=_create_service_inbound_api)
@pytest.fixture(scope='function')
def mock_delete_service_inbound_api(mocker):
return mocker.patch(
'app.service_api_client.delete_service_callback_api',
side_effect=lambda service_id: None
)
@pytest.fixture(scope='function')
def mock_update_service_inbound_api(mocker):
def _update_service_inbound_api(service_id, url, bearer_token, user_id, inbound_api_id):