Merge pull request #2948 from alphagov/csv-international-letters

Set postage and international for letters uploaded with a CSV
This commit is contained in:
Rebecca Law
2020-08-10 10:07:41 +01:00
committed by GitHub
3 changed files with 18 additions and 11 deletions

View File

@@ -340,9 +340,9 @@ def save_letter(
):
notification = encryption.decrypt(encrypted_notification)
recipient = PostalAddress.from_personalisation(
postal_address = PostalAddress.from_personalisation(
Columns(notification['personalisation'])
).normalised
)
service = dao_fetch_service_by_id(service_id)
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
@@ -354,8 +354,8 @@ def save_letter(
saved_notification = persist_notification(
template_id=notification['template'],
template_version=notification['template_version'],
postage=template.postage,
recipient=recipient,
postage=postal_address.postage if postal_address.international else template.postage,
recipient=postal_address.normalised,
service=service,
personalisation=notification['personalisation'],
notification_type=LETTER_TYPE,

View File

@@ -242,7 +242,7 @@ def validate_address(service, letter_data):
raise ValidationError(
message='Address lines must not start with any of the following characters: @ ( ) = [ ] ” \\ / ,'
)
if address.postage == 'united-kingdom':
return None # use postage from template
else:
if address.international:
return address.postage
else:
return None

View File

@@ -1035,8 +1035,14 @@ def test_save_letter_saves_letter_to_database(
assert notification_db.reply_to_text == contact_block.contact_block
@pytest.mark.parametrize('postage', ['first', 'second'])
def test_save_letter_saves_letter_to_database_with_correct_postage(mocker, notify_db_session, postage):
@pytest.mark.parametrize('last_line_of_address, postage, expected_postage, expected_international',
[('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])
template = create_template(service=service, template_type=LETTER_TYPE, postage=postage)
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(
template=letter_job.template,
to='Foo',
personalisation={'addressline1': 'Foo', 'addressline2': 'Bar', 'postcode': 'Flob'},
personalisation={'addressline1': 'Foo', 'addressline2': 'Bar', 'postcode': last_line_of_address},
job_id=letter_job.id,
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()
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):