mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-03 00:50:29 -04:00
handle invalid upload errors correctly
previously it assumed that invalid_pages would always exist, however it might be `None` if the error isn't on a specific page. Errors on specific pages include a page not being A4 or content being outside the boundary. Errors not on specific pages include the file not being a pdf, or containing too many pages
This commit is contained in:
@@ -629,13 +629,15 @@ LETTER_VALIDATION_MESSAGES = {
|
||||
|
||||
|
||||
def get_letter_validation_error(validation_message, invalid_pages=None, page_count=None):
|
||||
if not invalid_pages:
|
||||
invalid_pages = []
|
||||
if validation_message not in LETTER_VALIDATION_MESSAGES:
|
||||
return {'title': 'Validation failed'}
|
||||
|
||||
invalid_pages_are_or_is = 'is' if len(invalid_pages) == 1 else 'are'
|
||||
|
||||
invalid_pages = unescaped_formatted_list(
|
||||
invalid_pages or [],
|
||||
invalid_pages,
|
||||
before_each='',
|
||||
after_each='',
|
||||
prefix='page',
|
||||
|
||||
@@ -458,7 +458,7 @@ def test_get_letter_validation_error_for_unknown_error():
|
||||
),
|
||||
(
|
||||
'letter-too-long',
|
||||
[2],
|
||||
None,
|
||||
'Your letter is too long',
|
||||
(
|
||||
'Letters must be 10 pages or less. '
|
||||
@@ -471,7 +471,7 @@ def test_get_letter_validation_error_for_unknown_error():
|
||||
),
|
||||
(
|
||||
'unable-to-read-the-file',
|
||||
[2],
|
||||
None,
|
||||
'There’s a problem with your file',
|
||||
(
|
||||
'Notify cannot read this PDF.'
|
||||
|
||||
Reference in New Issue
Block a user