From b2ad7ff3cb61ed3fdbd6e349ae3aad5003e5a744 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 20 May 2020 11:18:15 +0100 Subject: [PATCH] Replace `format_recipient` with `PostalAddress.as_single_line` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ve refactored the code to display an address on a single line with commas into utils now. --- app/main/views/uploads.py | 19 +------------------ requirements-app.txt | 2 +- requirements.txt | 8 ++++---- tests/app/main/views/test_uploads.py | 13 ------------- 4 files changed, 6 insertions(+), 36 deletions(-) diff --git a/app/main/views/uploads.py b/app/main/views/uploads.py index d72baf691..0e29c13c2 100644 --- a/app/main/views/uploads.py +++ b/app/main/views/uploads.py @@ -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//preview-letter/") @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 ) diff --git a/requirements-app.txt b/requirements-app.txt index 0aad711d9..80a3f30f7 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -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 diff --git a/requirements.txt b/requirements.txt index 810a6e2b0..f5d52fee8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/tests/app/main/views/test_uploads.py b/tests/app/main/views/test_uploads.py index 69fb54481..941321500 100644 --- a/tests/app/main/views/test_uploads.py +++ b/tests/app/main/views/test_uploads.py @@ -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(),