mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Merge pull request #3240 from alphagov/recipient-address
Show the first line of the address from the to field.
This commit is contained in:
@@ -271,7 +271,8 @@ def test_letters_with_status_virus_scan_failed_shows_a_failure_description(
|
||||
mock_get_service_data_retention,
|
||||
mock_get_api_keys,
|
||||
):
|
||||
notifications = create_notifications(template_type='letter', status='virus-scan-failed', is_precompiled_letter=True)
|
||||
notifications = create_notifications(template_type='letter', status='virus-scan-failed', is_precompiled_letter=True,
|
||||
client_reference='client reference')
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
@@ -297,7 +298,8 @@ 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)
|
||||
notifications = create_notifications(template_type='letter', status=letter_status,
|
||||
is_precompiled_letter=True, client_reference='ref')
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
@@ -692,11 +694,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,
|
||||
@@ -704,12 +706,15 @@ def test_should_expected_hint_for_letters(
|
||||
mock_get_no_api_keys,
|
||||
mocker,
|
||||
is_precompiled_letter,
|
||||
expected_address,
|
||||
expected_hint
|
||||
):
|
||||
notifications = create_notifications(
|
||||
template_type='letter',
|
||||
subject=expected_hint,
|
||||
is_precompiled_letter=is_precompiled_letter,
|
||||
client_reference=expected_hint,
|
||||
to=expected_address
|
||||
)
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
@@ -719,4 +724,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
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import urllib
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
from flask import make_response, url_for
|
||||
from requests import RequestException
|
||||
|
||||
from app.main.views.uploads import format_recipient
|
||||
from app.utils import normalize_spaces
|
||||
from tests.conftest import SERVICE_ONE_ID
|
||||
|
||||
@@ -350,8 +352,11 @@ def test_uploaded_letter_preview(
|
||||
fake_uuid,
|
||||
):
|
||||
mocker.patch('app.main.views.uploads.service_api_client')
|
||||
recipient = 'Bugs Bunny\n123 Big Hole\rLooney Town'
|
||||
mocker.patch('app.main.views.uploads.get_letter_metadata', return_value={
|
||||
'filename': 'my_letter.pdf', 'page_count': '1', 'status': 'valid'})
|
||||
'filename': 'my_letter.pdf', 'page_count': '1', 'status': 'valid',
|
||||
'recipient': urllib.parse.quote(recipient)
|
||||
})
|
||||
|
||||
service_one['restricted'] = False
|
||||
client_request.login(active_user_with_permissions, service=service_one)
|
||||
@@ -455,7 +460,7 @@ def test_uploaded_letter_preview_image_does_not_show_overlay_if_no_content_outsi
|
||||
|
||||
|
||||
def test_send_uploaded_letter_sends_letter_and_redirects_to_notification_page(mocker, service_one, client_request):
|
||||
metadata = {'filename': 'my_file.pdf', 'page_count': '1', 'status': 'valid'}
|
||||
metadata = {'filename': 'my_file.pdf', 'page_count': '1', 'status': 'valid', 'recipient': 'address'}
|
||||
|
||||
mocker.patch('app.main.views.uploads.get_letter_pdf_and_metadata', return_value=('file', metadata))
|
||||
mock_send = mocker.patch('app.main.views.uploads.notification_api_client.send_precompiled_letter')
|
||||
@@ -475,7 +480,7 @@ def test_send_uploaded_letter_sends_letter_and_redirects_to_notification_page(mo
|
||||
_external=True
|
||||
)
|
||||
)
|
||||
mock_send.assert_called_once_with(SERVICE_ONE_ID, 'my_file.pdf', file_id, 'first')
|
||||
mock_send.assert_called_once_with(SERVICE_ONE_ID, 'my_file.pdf', file_id, 'first', 'address')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('permissions', [
|
||||
@@ -522,3 +527,15 @@ def test_send_uploaded_letter_when_metadata_states_pdf_is_invalid(mocker, servic
|
||||
_expected_status=403
|
||||
)
|
||||
assert not mock_send.called
|
||||
|
||||
|
||||
@pytest.mark.parametrize('original_address,expected_address', [
|
||||
('The Queen, Buckingham Palace, SW1 1AA', 'The Queen, Buckingham Palace, SW1 1AA'),
|
||||
('The Queen Buckingham Palace SW1 1AA', 'The Queen Buckingham Palace SW1 1AA'),
|
||||
('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
|
||||
|
||||
@@ -65,7 +65,8 @@ def test_send_precompiled_letter(mocker, logged_in_client, active_user_with_perm
|
||||
'abcd-1234',
|
||||
'my_file.pdf',
|
||||
'file-ID',
|
||||
'second'
|
||||
'second',
|
||||
'Bugs Bunny, 12 Hole Avenue, Looney Town'
|
||||
)
|
||||
mock_post.assert_called_once_with(
|
||||
url='/service/abcd-1234/send-pdf-letter',
|
||||
@@ -74,6 +75,7 @@ def test_send_precompiled_letter(mocker, logged_in_client, active_user_with_perm
|
||||
'file_id': 'file-ID',
|
||||
'created_by': active_user_with_permissions['id'],
|
||||
'postage': 'second',
|
||||
'recipient_address': 'Bugs Bunny, 12 Hole Avenue, Looney Town',
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -1,27 +1,29 @@
|
||||
import pytest
|
||||
import urllib
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from app.s3_client.s3_letter_upload_client import (
|
||||
format_recipient,
|
||||
upload_letter_to_s3,
|
||||
)
|
||||
from app.s3_client.s3_letter_upload_client import upload_letter_to_s3
|
||||
|
||||
|
||||
def test_upload_letter_to_s3(mocker):
|
||||
s3_mock = mocker.patch('app.s3_client.s3_letter_upload_client.utils_s3upload')
|
||||
|
||||
recipient = 'Bugs Bunny\n123 Big Hole\nLooney Town'
|
||||
upload_letter_to_s3(
|
||||
'pdf_data',
|
||||
file_location='service_id/upload_id.pdf',
|
||||
status='valid',
|
||||
page_count=3,
|
||||
filename='my_doc')
|
||||
filename='my_doc',
|
||||
recipient=recipient
|
||||
)
|
||||
|
||||
s3_mock.assert_called_once_with(
|
||||
bucket_name=current_app.config['TRANSIENT_UPLOADED_LETTERS'],
|
||||
file_location='service_id/upload_id.pdf',
|
||||
filedata='pdf_data',
|
||||
metadata={'status': 'valid', 'page_count': '3', 'filename': 'my_doc'},
|
||||
metadata={'status': 'valid', 'page_count': '3', 'filename': 'my_doc',
|
||||
'recipient': urllib.parse.quote(recipient)},
|
||||
region=current_app.config['AWS_REGION']
|
||||
)
|
||||
|
||||
@@ -51,15 +53,3 @@ def test_upload_letter_to_s3_with_message_and_invalid_pages(mocker):
|
||||
},
|
||||
region=current_app.config['AWS_REGION']
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('original_address,expected_address', [
|
||||
('The Queen, Buckingham Palace, SW1 1AA', 'The Queen, Buckingham Palace, SW1 1AA'),
|
||||
('The Queen Buckingham Palace SW1 1AA', 'The Queen Buckingham Palace SW1 1AA'),
|
||||
('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'),
|
||||
("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(original_address) == expected_address
|
||||
|
||||
@@ -55,6 +55,7 @@ def _get_notifications_csv(
|
||||
"row_number": row_number + i,
|
||||
"to": recipient,
|
||||
"recipient": recipient,
|
||||
"client_reference": 'ref 1234',
|
||||
"template_name": template_name,
|
||||
"template_type": template_type,
|
||||
"template": {"name": template_name, "template_type": template_type},
|
||||
@@ -160,14 +161,14 @@ def test_spreadsheet_checks_for_bad_arguments(args, kwargs):
|
||||
@pytest.mark.parametrize('created_by_name, expected_content', [
|
||||
(
|
||||
None, [
|
||||
'Recipient,Template,Type,Sent by,Sent by email,Job,Status,Time\n',
|
||||
'foo@bar.com,foo,sms,,sender@email.gov.uk,,Delivered,1943-04-19 12:00:00\r\n',
|
||||
'Recipient,Reference,Template,Type,Sent by,Sent by email,Job,Status,Time\n',
|
||||
'foo@bar.com,ref 1234,foo,sms,,sender@email.gov.uk,,Delivered,1943-04-19 12:00:00\r\n',
|
||||
]
|
||||
),
|
||||
(
|
||||
'Anne Example', [
|
||||
'Recipient,Template,Type,Sent by,Sent by email,Job,Status,Time\n',
|
||||
'foo@bar.com,foo,sms,Anne Example,sender@email.gov.uk,,Delivered,1943-04-19 12:00:00\r\n',
|
||||
'Recipient,Reference,Template,Type,Sent by,Sent by email,Job,Status,Time\n',
|
||||
'foo@bar.com,ref 1234,foo,sms,Anne Example,sender@email.gov.uk,,Delivered,1943-04-19 12:00:00\r\n',
|
||||
]
|
||||
),
|
||||
])
|
||||
@@ -183,7 +184,7 @@ def test_generate_notifications_csv_without_job(
|
||||
created_by_name=created_by_name,
|
||||
created_by_email_address="sender@email.gov.uk",
|
||||
job_id=None,
|
||||
job_name=None,
|
||||
job_name=None
|
||||
)
|
||||
)
|
||||
assert list(generate_notifications_csv(service_id=fake_uuid)) == expected_content
|
||||
|
||||
Reference in New Issue
Block a user