mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 01:56:03 -04:00
Merge pull request #2748 from alphagov/format-postcode-for-csvs
Format postcode for CSV letter rows
This commit is contained in:
@@ -4,6 +4,7 @@ from collections import namedtuple, defaultdict
|
|||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from notifications_utils.recipients import (
|
from notifications_utils.recipients import (
|
||||||
|
format_postcode_for_printing,
|
||||||
RecipientCSV
|
RecipientCSV
|
||||||
)
|
)
|
||||||
from notifications_utils.statsd_decorators import statsd
|
from notifications_utils.statsd_decorators import statsd
|
||||||
@@ -305,6 +306,10 @@ def save_letter(
|
|||||||
# we store the recipient as just the first item of the person's address
|
# we store the recipient as just the first item of the person's address
|
||||||
recipient = notification['personalisation']['addressline1']
|
recipient = notification['personalisation']['addressline1']
|
||||||
|
|
||||||
|
notification['personalisation']['postcode'] = format_postcode_for_printing(
|
||||||
|
notification['personalisation']['postcode']
|
||||||
|
)
|
||||||
|
|
||||||
service = dao_fetch_service_by_id(service_id)
|
service = dao_fetch_service_by_id(service_id)
|
||||||
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
|
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
|
||||||
|
|
||||||
|
|||||||
@@ -27,4 +27,4 @@ notifications-python-client==5.5.1
|
|||||||
awscli-cwlogs>=1.4,<1.5
|
awscli-cwlogs>=1.4,<1.5
|
||||||
|
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@36.6.2#egg=notifications-utils==36.6.2
|
git+https://github.com/alphagov/notifications-utils.git@36.9.0#egg=notifications-utils==36.9.0
|
||||||
|
|||||||
@@ -29,23 +29,23 @@ notifications-python-client==5.5.1
|
|||||||
awscli-cwlogs>=1.4,<1.5
|
awscli-cwlogs>=1.4,<1.5
|
||||||
|
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@36.6.2#egg=notifications-utils==36.6.2
|
git+https://github.com/alphagov/notifications-utils.git@36.9.0#egg=notifications-utils==36.9.0
|
||||||
|
|
||||||
## The following requirements were added by pip freeze:
|
## The following requirements were added by pip freeze:
|
||||||
alembic==1.4.1
|
alembic==1.4.1
|
||||||
amqp==1.4.9
|
amqp==1.4.9
|
||||||
anyjson==0.3.3
|
anyjson==0.3.3
|
||||||
attrs==19.3.0
|
attrs==19.3.0
|
||||||
awscli==1.18.16
|
awscli==1.18.20
|
||||||
bcrypt==3.1.7
|
bcrypt==3.1.7
|
||||||
billiard==3.3.0.23
|
billiard==3.3.0.23
|
||||||
bleach==3.1.1
|
bleach==3.1.1
|
||||||
boto==2.49.0
|
boto==2.49.0
|
||||||
boto3==1.10.38
|
boto3==1.10.38
|
||||||
botocore==1.15.16
|
botocore==1.15.20
|
||||||
certifi==2019.11.28
|
certifi==2019.11.28
|
||||||
chardet==3.0.4
|
chardet==3.0.4
|
||||||
click==7.1
|
click==7.1.1
|
||||||
colorama==0.4.3
|
colorama==0.4.3
|
||||||
dnspython==1.16.0
|
dnspython==1.16.0
|
||||||
docutils==0.15.2
|
docutils==0.15.2
|
||||||
|
|||||||
@@ -961,7 +961,7 @@ def test_save_letter_saves_letter_to_database(mocker, notify_db_session):
|
|||||||
'addressline4': 'Wibble',
|
'addressline4': 'Wibble',
|
||||||
'addressline5': 'Wobble',
|
'addressline5': 'Wobble',
|
||||||
'addressline6': 'Wubble',
|
'addressline6': 'Wubble',
|
||||||
'postcode': 'Flob',
|
'postcode': 'SE1 2SA',
|
||||||
}
|
}
|
||||||
notification_json = _notification_json(
|
notification_json = _notification_json(
|
||||||
template=job.template,
|
template=job.template,
|
||||||
@@ -1021,6 +1021,31 @@ def test_save_letter_saves_letter_to_database_with_correct_postage(mocker, notif
|
|||||||
assert notification_db.postage == postage
|
assert notification_db.postage == postage
|
||||||
|
|
||||||
|
|
||||||
|
def test_save_letter_saves_letter_to_database_with_formatted_postcode(mocker, notify_db_session):
|
||||||
|
service = create_service(service_permissions=[LETTER_TYPE])
|
||||||
|
template = create_template(service=service, template_type=LETTER_TYPE)
|
||||||
|
letter_job = create_job(template=template)
|
||||||
|
|
||||||
|
mocker.patch('app.celery.tasks.letters_pdf_tasks.create_letters_pdf.apply_async')
|
||||||
|
notification_json = _notification_json(
|
||||||
|
template=letter_job.template,
|
||||||
|
to='Foo',
|
||||||
|
personalisation={'addressline1': 'Foo', 'addressline2': 'Bar', 'postcode': 'se1 64sa'},
|
||||||
|
job_id=letter_job.id,
|
||||||
|
row_number=1
|
||||||
|
)
|
||||||
|
notification_id = uuid.uuid4()
|
||||||
|
save_letter(
|
||||||
|
letter_job.service_id,
|
||||||
|
notification_id,
|
||||||
|
encryption.encrypt(notification_json),
|
||||||
|
)
|
||||||
|
|
||||||
|
notification_db = Notification.query.one()
|
||||||
|
assert notification_db.id == notification_id
|
||||||
|
assert notification_db.personalisation["postcode"] == "SE16 4SA"
|
||||||
|
|
||||||
|
|
||||||
def test_save_letter_saves_letter_to_database_right_reply_to(mocker, notify_db_session):
|
def test_save_letter_saves_letter_to_database_right_reply_to(mocker, notify_db_session):
|
||||||
service = create_service()
|
service = create_service()
|
||||||
create_letter_contact(service=service, contact_block="Address contact", is_default=True)
|
create_letter_contact(service=service, contact_block="Address contact", is_default=True)
|
||||||
@@ -1037,7 +1062,7 @@ def test_save_letter_saves_letter_to_database_right_reply_to(mocker, notify_db_s
|
|||||||
'addressline4': 'Wibble',
|
'addressline4': 'Wibble',
|
||||||
'addressline5': 'Wobble',
|
'addressline5': 'Wobble',
|
||||||
'addressline6': 'Wubble',
|
'addressline6': 'Wubble',
|
||||||
'postcode': 'Flob',
|
'postcode': 'SE1 3WS',
|
||||||
}
|
}
|
||||||
notification_json = _notification_json(
|
notification_json = _notification_json(
|
||||||
template=job.template,
|
template=job.template,
|
||||||
|
|||||||
Reference in New Issue
Block a user