mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 16:31:15 -05:00
Set postage for templated letters when the address is not from the united-kingdom.
If the address is from the united-kingdom use the postage from the template.
This commit is contained in:
@@ -14,6 +14,7 @@ def create_letter_notification(
|
|||||||
reply_to_text=None,
|
reply_to_text=None,
|
||||||
billable_units=None,
|
billable_units=None,
|
||||||
updated_at=None,
|
updated_at=None,
|
||||||
|
postage=None
|
||||||
):
|
):
|
||||||
notification = persist_notification(
|
notification = persist_notification(
|
||||||
template_id=template.id,
|
template_id=template.id,
|
||||||
@@ -33,7 +34,9 @@ def create_letter_notification(
|
|||||||
status=status,
|
status=status,
|
||||||
reply_to_text=reply_to_text,
|
reply_to_text=reply_to_text,
|
||||||
billable_units=billable_units,
|
billable_units=billable_units,
|
||||||
postage=letter_data.get('postage'),
|
# letter_data.get('postage') is only set for precompiled letters
|
||||||
|
# letters from a template will pass in 'europe' or 'rest-of-world' if None then use postage from template
|
||||||
|
postage=postage or letter_data.get('postage'),
|
||||||
updated_at=updated_at
|
updated_at=updated_at
|
||||||
)
|
)
|
||||||
return notification
|
return notification
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ def process_letter_notification(
|
|||||||
template=template,
|
template=template,
|
||||||
reply_to_text=reply_to_text)
|
reply_to_text=reply_to_text)
|
||||||
|
|
||||||
validate_address(service, letter_data)
|
postage = validate_address(service, letter_data)
|
||||||
|
|
||||||
test_key = api_key.key_type == KEY_TYPE_TEST
|
test_key = api_key.key_type == KEY_TYPE_TEST
|
||||||
|
|
||||||
@@ -362,7 +362,8 @@ def process_letter_notification(
|
|||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
status=status,
|
status=status,
|
||||||
reply_to_text=reply_to_text,
|
reply_to_text=reply_to_text,
|
||||||
updated_at=updated_at
|
updated_at=updated_at,
|
||||||
|
postage=postage
|
||||||
)
|
)
|
||||||
|
|
||||||
get_pdf_for_templated_letter.apply_async(
|
get_pdf_for_templated_letter.apply_async(
|
||||||
@@ -413,6 +414,10 @@ 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':
|
||||||
|
return None # use postage from template
|
||||||
|
else:
|
||||||
|
return address.postage
|
||||||
|
|
||||||
|
|
||||||
def process_precompiled_letter_notifications(*, letter_data, api_key, service, template, reply_to_text):
|
def process_precompiled_letter_notifications(*, letter_data, api_key, service, template, reply_to_text):
|
||||||
|
|||||||
@@ -174,6 +174,30 @@ def test_post_letter_notification_stores_country(
|
|||||||
'Kronprinzenpalais\n'
|
'Kronprinzenpalais\n'
|
||||||
'Germany'
|
'Germany'
|
||||||
)
|
)
|
||||||
|
assert notification.postage == 'europe'
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_letter_notification_international_sets_rest_of_world(
|
||||||
|
client, notify_db_session, mocker
|
||||||
|
):
|
||||||
|
service = create_service(service_permissions=[LETTER_TYPE, INTERNATIONAL_LETTERS])
|
||||||
|
template = create_template(service, template_type="letter")
|
||||||
|
mocker.patch('app.celery.tasks.letters_pdf_tasks.get_pdf_for_templated_letter.apply_async')
|
||||||
|
data = {
|
||||||
|
'template_id': str(template.id),
|
||||||
|
'personalisation': {
|
||||||
|
'address_line_1': 'Prince Harry',
|
||||||
|
'address_line_2': 'Toronto',
|
||||||
|
'address_line_5': 'Canada',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resp_json = letter_request(client, data, service_id=service.id)
|
||||||
|
|
||||||
|
assert validate(resp_json, post_letter_response) == resp_json
|
||||||
|
notification = Notification.query.one()
|
||||||
|
|
||||||
|
assert notification.postage == 'rest-of-world'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('permissions, personalisation, expected_error', (
|
@pytest.mark.parametrize('permissions, personalisation, expected_error', (
|
||||||
|
|||||||
Reference in New Issue
Block a user