mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
Show error message if precompiled PDF cannot be opened
If PDF files have a validation error which means that they can't be opened by PyPDF2 we would previously show the 500 status error page. We now catch PyPDF2.utils.PdfReadErrors so that we can display a custom error message on the notification page instead.
This commit is contained in:
@@ -7,6 +7,7 @@ import pytest
|
||||
from flask import url_for
|
||||
from freezegun import freeze_time
|
||||
from notifications_python_client.errors import APIError
|
||||
from PyPDF2.utils import PdfReadError
|
||||
|
||||
from app.main.views.notifications import get_letter_printing_statement
|
||||
from tests.conftest import (
|
||||
@@ -398,6 +399,36 @@ def test_should_show_preview_error_image_letter_notification_on_preview_error(
|
||||
assert response.get_data(as_text=True) == 'preview error image'
|
||||
|
||||
|
||||
def test_notifification_page_shows_error_message_if_precompiled_letter_cannot_be_opened(
|
||||
client_request,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
):
|
||||
mock_get_notification(
|
||||
mocker,
|
||||
fake_uuid,
|
||||
notification_status='validation-failed',
|
||||
template_type='letter',
|
||||
is_precompiled_letter=True,
|
||||
)
|
||||
mocker.patch(
|
||||
'app.main.views.notifications.view_letter_notification_as_preview',
|
||||
side_effect=PdfReadError()
|
||||
)
|
||||
mocker.patch(
|
||||
'app.main.views.notifications.pdf_page_count',
|
||||
side_effect=PdfReadError()
|
||||
)
|
||||
page = client_request.get(
|
||||
'main.view_notification',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
notification_id=fake_uuid,
|
||||
)
|
||||
|
||||
error_message = page.find('p', class_='notification-status-cancelled').text
|
||||
assert normalize_spaces(error_message) == "Couldn’t read this file"
|
||||
|
||||
|
||||
def test_should_404_for_unknown_extension(
|
||||
client_request,
|
||||
fake_uuid,
|
||||
|
||||
Reference in New Issue
Block a user