mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 17:38:50 -04:00
Replace format_recipient with PostalAddress.as_single_line
We’ve refactored the code to display an address on a single line with commas into utils now.
This commit is contained in:
@@ -252,23 +252,6 @@ def _get_error_from_upload_form(form_errors):
|
||||
return error
|
||||
|
||||
|
||||
def format_recipient(address):
|
||||
'''
|
||||
To format the recipient we need to:
|
||||
- remove new line characters
|
||||
- remove whitespace around the lines
|
||||
- join the address lines, separated by a comma
|
||||
'''
|
||||
if not address:
|
||||
return address
|
||||
stripped_address_lines_no_trailing_commas = [
|
||||
line.lstrip().rstrip(' ,')
|
||||
for line in address.splitlines() if line
|
||||
]
|
||||
one_line_address = ', '.join(stripped_address_lines_no_trailing_commas)
|
||||
return one_line_address
|
||||
|
||||
|
||||
@main.route("/services/<uuid:service_id>/preview-letter/<uuid:file_id>")
|
||||
@user_has_permissions('send_messages')
|
||||
def uploaded_letter_preview(service_id, file_id):
|
||||
@@ -316,7 +299,7 @@ def uploaded_letter_preview(service_id, file_id):
|
||||
message=error_message,
|
||||
error_code=error_shortcode,
|
||||
form=form,
|
||||
recipient=format_recipient(postal_address.raw_address),
|
||||
recipient=postal_address.as_single_line,
|
||||
international=postal_address.international,
|
||||
re_upload_form=re_upload_form
|
||||
)
|
||||
|
||||
@@ -23,5 +23,5 @@ notifications-python-client==5.5.1
|
||||
awscli-cwlogs>=1.4,<1.5
|
||||
itsdangerous==1.1.0
|
||||
|
||||
git+https://github.com/alphagov/notifications-utils.git@39.2.0#egg=notifications-utils==39.2.0
|
||||
git+https://github.com/alphagov/notifications-utils.git@39.3.0#egg=notifications-utils==39.3.0
|
||||
git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha
|
||||
|
||||
@@ -25,14 +25,14 @@ notifications-python-client==5.5.1
|
||||
awscli-cwlogs>=1.4,<1.5
|
||||
itsdangerous==1.1.0
|
||||
|
||||
git+https://github.com/alphagov/notifications-utils.git@39.2.0#egg=notifications-utils==39.2.0
|
||||
git+https://github.com/alphagov/notifications-utils.git@39.3.0#egg=notifications-utils==39.3.0
|
||||
git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha
|
||||
|
||||
## The following requirements were added by pip freeze:
|
||||
awscli==1.18.61
|
||||
awscli==1.18.63
|
||||
bleach==3.1.4
|
||||
boto3==1.10.38
|
||||
botocore==1.16.11
|
||||
botocore==1.16.13
|
||||
certifi==2020.4.5.1
|
||||
chardet==3.0.4
|
||||
click==7.1.2
|
||||
@@ -49,7 +49,7 @@ jdcal==1.4.1
|
||||
Jinja2==2.11.2
|
||||
jmespath==0.10.0
|
||||
lml==0.0.9
|
||||
lxml==4.5.0
|
||||
lxml==4.5.1
|
||||
MarkupSafe==1.1.1
|
||||
mistune==0.8.4
|
||||
monotonic==1.5
|
||||
|
||||
@@ -8,7 +8,6 @@ from flask import make_response, url_for
|
||||
from freezegun import freeze_time
|
||||
from requests import RequestException
|
||||
|
||||
from app.main.views.uploads import format_recipient
|
||||
from app.s3_client.s3_letter_upload_client import LetterMetadata
|
||||
from app.utils import normalize_spaces
|
||||
from tests.conftest import (
|
||||
@@ -947,18 +946,6 @@ def test_send_uploaded_letter_when_metadata_states_pdf_is_invalid(
|
||||
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(original_address) == expected_address
|
||||
|
||||
|
||||
@pytest.mark.parametrize('user', (
|
||||
create_active_caseworking_user(),
|
||||
create_active_user_with_permissions(),
|
||||
|
||||
Reference in New Issue
Block a user