diff --git a/app/utils.py b/app/utils.py index 8c1d737af..59f236101 100644 --- a/app/utils.py +++ b/app/utils.py @@ -23,6 +23,7 @@ from notifications_utils.formatters import ( unescaped_formatted_list, ) from notifications_utils.letter_timings import letter_can_be_cancelled +from notifications_utils.postal_address import PostalAddress from notifications_utils.recipients import RecipientCSV from notifications_utils.take import Take from notifications_utils.template import ( @@ -658,6 +659,28 @@ LETTER_VALIDATION_MESSAGES = { 'summary': ( 'Validation failed because the last line of the address is not a real UK postcode.' ), + }, + 'not-enough-address-lines': { + 'title': 'There’s a problem with the address for this letter', + 'detail': ( + f'The address must be at least {PostalAddress.MIN_LINES} ' + f'lines long.' + ), + 'summary': ( + f'Validation failed because the address must be at least ' + f'{PostalAddress.MIN_LINES} lines long.' + ), + }, + 'too-many-address-lines': { + 'title': 'There’s a problem with the address for this letter', + 'detail': ( + f'The address must be no more than {PostalAddress.MAX_LINES} ' + f'lines long.' + ), + 'summary': ( + f'Validation failed because the address must be no more ' + f'than {PostalAddress.MAX_LINES} lines long.' + ), } } diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index 58c1a3079..b91e473d6 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -507,6 +507,28 @@ def test_get_letter_validation_error_for_unknown_error(): 'Validation failed because the last line of the address is not a real UK postcode.' ), ), + ( + 'not-enough-address-lines', + None, + 'There’s a problem with the address for this letter', + ( + 'The address must be at least 3 lines long.' + ), + ( + 'Validation failed because the address must be at least 3 lines long.' + ), + ), + ( + 'too-many-address-lines', + None, + 'There’s a problem with the address for this letter', + ( + 'The address must be no more than 7 lines long.' + ), + ( + 'Validation failed because the address must be no more than 7 lines long.' + ), + ), ]) def test_get_letter_validation_error_for_known_errors( client_request,