From 4e1fcfbff1822b12834e39cd58b0b350d46dcec8 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Mon, 27 Jan 2020 15:07:40 +0000 Subject: [PATCH] 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 --- app/utils.py | 4 +++- tests/app/test_utils.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/utils.py b/app/utils.py index 3f8a3b599..29154c7b6 100644 --- a/app/utils.py +++ b/app/utils.py @@ -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', diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index a8dc0755b..e04a44fa8 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -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.'