mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
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:
23
app/utils.py
23
app/utils.py
@@ -23,6 +23,7 @@ from notifications_utils.formatters import (
|
|||||||
unescaped_formatted_list,
|
unescaped_formatted_list,
|
||||||
)
|
)
|
||||||
from notifications_utils.letter_timings import letter_can_be_cancelled
|
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.recipients import RecipientCSV
|
||||||
from notifications_utils.take import Take
|
from notifications_utils.take import Take
|
||||||
from notifications_utils.template import (
|
from notifications_utils.template import (
|
||||||
@@ -658,6 +659,28 @@ LETTER_VALIDATION_MESSAGES = {
|
|||||||
'summary': (
|
'summary': (
|
||||||
'Validation failed because the last line of the address is not a real UK postcode.'
|
'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.'
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.'
|
'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(
|
def test_get_letter_validation_error_for_known_errors(
|
||||||
client_request,
|
client_request,
|
||||||
|
|||||||
Reference in New Issue
Block a user