Merge pull request #2746 from alphagov/fix-non-content-outside-errors

Undo bug for previewing precompiled letters
This commit is contained in:
David McDonald
2020-03-11 15:29:10 +00:00
committed by GitHub
2 changed files with 8 additions and 3 deletions

View File

@@ -263,7 +263,10 @@ def preview_letter_template_by_notification_id(service_id, notification_id, file
if file_type == 'png':
try:
pdf_page = extract_page_from_pdf(BytesIO(pdf_file), int(page_number) - 1)
content = pdf_page if page_is_in_invalid_pages else base64.b64encode(pdf_page).decode('utf-8')
if content_outside_printable_area and page_is_in_invalid_pages:
content = pdf_page
else:
content = base64.b64encode(pdf_page).decode('utf-8')
except PdfReadError as e:
raise InvalidRequest(
'Error extracting requested page from PDF file for notification_id {} type {} {}'.format(

View File

@@ -1149,6 +1149,8 @@ def test_preview_letter_template_precompiled_s3_error(
("", "", 'precompiled-preview.png'),
# page is valid, no overlay shown
("1", "", 'precompiled-preview.png'),
# page is invalid but not because content is outside printable area so no overlay
("1", "letter-not-a4-portrait-oriented", 'precompiled-preview.png'),
# page is invalid, overlay shown
("1", "content-outside-printable-area", 'precompiled/overlay.png?page_number=1'),
# page is valid, no overlay shown
@@ -1157,7 +1159,7 @@ def test_preview_letter_template_precompiled_s3_error(
("3", "content-outside-printable-area", 'precompiled/overlay.png?page_number=3'),
]
)
def test_preview_letter_template_precompiled_for_png_file_shows_overlay_where_appropriate(
def test_preview_letter_template_precompiled_for_png_shows_overlay_on_pages_with_content_outside_printable_area(
notify_api,
client,
admin_request,
@@ -1227,7 +1229,7 @@ def test_preview_letter_template_precompiled_for_png_file_shows_overlay_where_ap
"[2,4]", # it shouldn't make a difference if the error was on the first page or not
]
)
def test_preview_letter_template_precompiled_for_pdf_file_shows_overlay_if_content_outside_printable_area(
def test_preview_letter_template_precompiled_for_pdf_shows_overlay_on_all_pages_if_content_outside_printable_area(
notify_api,
client,
admin_request,