mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-06 18:38:26 -04:00
Set postage and international for letters uploaded with a CSV
If the letter is outside of the United Kingdom, set the postage and international flag.
This commit is contained in:
@@ -340,9 +340,9 @@ def save_letter(
|
|||||||
):
|
):
|
||||||
notification = encryption.decrypt(encrypted_notification)
|
notification = encryption.decrypt(encrypted_notification)
|
||||||
|
|
||||||
recipient = PostalAddress.from_personalisation(
|
postal_address = PostalAddress.from_personalisation(
|
||||||
Columns(notification['personalisation'])
|
Columns(notification['personalisation'])
|
||||||
).normalised
|
)
|
||||||
|
|
||||||
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'])
|
||||||
@@ -354,8 +354,8 @@ def save_letter(
|
|||||||
saved_notification = persist_notification(
|
saved_notification = persist_notification(
|
||||||
template_id=notification['template'],
|
template_id=notification['template'],
|
||||||
template_version=notification['template_version'],
|
template_version=notification['template_version'],
|
||||||
postage=template.postage,
|
postage=postal_address.postage if postal_address.international else template.postage,
|
||||||
recipient=recipient,
|
recipient=postal_address.normalised,
|
||||||
service=service,
|
service=service,
|
||||||
personalisation=notification['personalisation'],
|
personalisation=notification['personalisation'],
|
||||||
notification_type=LETTER_TYPE,
|
notification_type=LETTER_TYPE,
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ def validate_address(service, letter_data):
|
|||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
message='Address lines must not start with any of the following characters: @ ( ) = [ ] ” \\ / ,'
|
message='Address lines must not start with any of the following characters: @ ( ) = [ ] ” \\ / ,'
|
||||||
)
|
)
|
||||||
if address.postage == 'united-kingdom':
|
if address.international:
|
||||||
return None # use postage from template
|
|
||||||
else:
|
|
||||||
return address.postage
|
return address.postage
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|||||||
@@ -1035,8 +1035,14 @@ def test_save_letter_saves_letter_to_database(
|
|||||||
assert notification_db.reply_to_text == contact_block.contact_block
|
assert notification_db.reply_to_text == contact_block.contact_block
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('postage', ['first', 'second'])
|
@pytest.mark.parametrize('last_line_of_address, postage, expected_postage, expected_international',
|
||||||
def test_save_letter_saves_letter_to_database_with_correct_postage(mocker, notify_db_session, postage):
|
[('SW1 1AA', 'first', 'first', False),
|
||||||
|
('SW1 1AA', 'second', 'second', False),
|
||||||
|
('New Zealand', 'second', 'rest-of-world', True),
|
||||||
|
('France', 'first', 'europe', True)])
|
||||||
|
def test_save_letter_saves_letter_to_database_with_correct_postage(
|
||||||
|
mocker, notify_db_session, last_line_of_address, postage, expected_postage, expected_international
|
||||||
|
):
|
||||||
service = create_service(service_permissions=[LETTER_TYPE])
|
service = create_service(service_permissions=[LETTER_TYPE])
|
||||||
template = create_template(service=service, template_type=LETTER_TYPE, postage=postage)
|
template = create_template(service=service, template_type=LETTER_TYPE, postage=postage)
|
||||||
letter_job = create_job(template=template)
|
letter_job = create_job(template=template)
|
||||||
@@ -1045,7 +1051,7 @@ def test_save_letter_saves_letter_to_database_with_correct_postage(mocker, notif
|
|||||||
notification_json = _notification_json(
|
notification_json = _notification_json(
|
||||||
template=letter_job.template,
|
template=letter_job.template,
|
||||||
to='Foo',
|
to='Foo',
|
||||||
personalisation={'addressline1': 'Foo', 'addressline2': 'Bar', 'postcode': 'Flob'},
|
personalisation={'addressline1': 'Foo', 'addressline2': 'Bar', 'postcode': last_line_of_address},
|
||||||
job_id=letter_job.id,
|
job_id=letter_job.id,
|
||||||
row_number=1
|
row_number=1
|
||||||
)
|
)
|
||||||
@@ -1058,7 +1064,8 @@ def test_save_letter_saves_letter_to_database_with_correct_postage(mocker, notif
|
|||||||
|
|
||||||
notification_db = Notification.query.one()
|
notification_db = Notification.query.one()
|
||||||
assert notification_db.id == notification_id
|
assert notification_db.id == notification_id
|
||||||
assert notification_db.postage == postage
|
assert notification_db.postage == expected_postage
|
||||||
|
assert notification_db.international == expected_international
|
||||||
|
|
||||||
|
|
||||||
def test_save_letter_saves_letter_to_database_with_formatted_postcode(mocker, notify_db_session):
|
def test_save_letter_saves_letter_to_database_with_formatted_postcode(mocker, notify_db_session):
|
||||||
|
|||||||
Reference in New Issue
Block a user