Get ready to error for precompiled letters with bad addresses

Template preview is going to start returning these errors; we need to be
ready to handle them.
This commit is contained in:
Chris Hill-Scott
2020-04-03 14:13:44 +01:00
parent c646c16067
commit 54d7c6fcbd
2 changed files with 45 additions and 0 deletions

View File

@@ -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': 'Theres 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': 'Theres 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.'
),
}
}

View File

@@ -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,
'Theres 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,
'Theres 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,