Save recipient address in the "to" field of a notification

When a precompiled letter is sent via the admin app, we now pass in the address which can be set in the Notifications.to field.
Once a precompiled letters sent by the API has passed validation we can set the address in Notifications.to field.

The celery tasks to validate precompiled letters sent by the API will be done in another PR.
This commit is contained in:
Rebecca Law
2020-01-02 16:35:18 +00:00
parent 5ebd9a473c
commit bb2b514e12
6 changed files with 29 additions and 15 deletions

View File

@@ -22,7 +22,8 @@ def test_send_pdf_letter_notification_raises_error_if_service_does_not_have_perm
permissions,
):
service = create_service(service_permissions=permissions)
post_data = {'filename': 'valid.pdf', 'created_by': fake_uuid, 'file_id': fake_uuid, 'postage': 'first'}
post_data = {'filename': 'valid.pdf', 'created_by': fake_uuid, 'file_id': fake_uuid, 'postage': 'first',
'recipient_address': 'Bugs%20Bunny%0A123%20Main%20Street%0ALooney%20Town'}
with pytest.raises(BadRequestError):
send_pdf_letter_notification(service.id, post_data)
@@ -36,7 +37,8 @@ def test_send_pdf_letter_notification_raises_error_if_service_is_over_daily_mess
mocker.patch(
'app.service.send_notification.check_service_over_daily_message_limit',
side_effect=TooManyRequestsError(10))
post_data = {'filename': 'valid.pdf', 'created_by': fake_uuid, 'file_id': fake_uuid, 'postage': 'first'}
post_data = {'filename': 'valid.pdf', 'created_by': fake_uuid, 'file_id': fake_uuid, 'postage': 'first',
'recipient_address': 'Bugs%20Bunny%0A123%20Main%20Street%0ALooney%20Town'}
with pytest.raises(TooManyRequestsError):
send_pdf_letter_notification(sample_service_full_permissions.id, post_data)
@@ -45,7 +47,8 @@ def test_send_pdf_letter_notification_raises_error_if_service_is_over_daily_mess
def test_send_pdf_letter_notification_validates_created_by(
sample_service_full_permissions, fake_uuid, sample_user
):
post_data = {'filename': 'valid.pdf', 'created_by': sample_user.id, 'file_id': fake_uuid, 'postage': 'first'}
post_data = {'filename': 'valid.pdf', 'created_by': sample_user.id, 'file_id': fake_uuid, 'postage': 'first',
'recipient_address': 'Bugs%20Bunny%0A123%20Main%20Street%0ALooney%20Town'}
with pytest.raises(BadRequestError):
send_pdf_letter_notification(sample_service_full_permissions.id, post_data)
@@ -58,7 +61,8 @@ def test_send_pdf_letter_notification_raises_error_if_service_in_trial_mode(
):
sample_service_full_permissions.restricted = True
user = sample_service_full_permissions.users[0]
post_data = {'filename': 'valid.pdf', 'created_by': user.id, 'file_id': fake_uuid}
post_data = {'filename': 'valid.pdf', 'created_by': user.id, 'file_id': fake_uuid,
'recipient_address': 'Bugs%20Bunny%0A123%20Main%20Street%0ALooney%20Town'}
with pytest.raises(BadRequestError) as e:
send_pdf_letter_notification(sample_service_full_permissions.id, post_data)
@@ -72,7 +76,8 @@ def test_send_pdf_letter_notification_raises_error_when_pdf_is_not_in_transient_
notify_user,
):
user = sample_service_full_permissions.users[0]
post_data = {'filename': 'valid.pdf', 'created_by': user.id, 'file_id': fake_uuid, 'postage': 'first'}
post_data = {'filename': 'valid.pdf', 'created_by': user.id, 'file_id': fake_uuid, 'postage': 'first',
'recipient_address': 'Bugs%20Bunny%0A123%20Main%20Street%0ALooney%20Town'}
mocker.patch('app.service.send_notification.utils_s3download', side_effect=S3ObjectNotFound({}, ''))
with pytest.raises(S3ObjectNotFound):
@@ -88,7 +93,8 @@ def test_send_pdf_letter_notification_creates_notification_and_moves_letter(
user = sample_service_full_permissions.users[0]
filename = 'valid.pdf'
file_id = uuid.uuid4()
post_data = {'filename': filename, 'created_by': user.id, 'file_id': file_id, 'postage': 'second'}
post_data = {'filename': filename, 'created_by': user.id, 'file_id': file_id, 'postage': 'second',
'recipient_address': 'Bugs%20Bunny%0A123%20Main%20Street%0ALooney%20Town'}
mocker.patch('app.service.send_notification.utils_s3download')
mocker.patch('app.service.send_notification.get_page_count', return_value=1)
@@ -105,7 +111,8 @@ def test_send_pdf_letter_notification_creates_notification_and_moves_letter(
assert notification.postage == 'second'
assert notification.notification_type == LETTER_TYPE
assert notification.billable_units == 1
assert notification.to == filename
assert notification.to == "Bugs Bunny\n123 Main Street\nLooney Town"
assert notification.service_id == sample_service_full_permissions.id
assert result == {'id': str(notification.id)}