mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 00:41:35 -05:00
Call overlaid preview for precompiled letters that fail validation
Also test precompiled letter preview with overlay
This commit is contained in:
@@ -249,10 +249,18 @@ def preview_letter_template_by_notification_id(service_id, notification_id, file
|
|||||||
status_code=500
|
status_code=500
|
||||||
)
|
)
|
||||||
|
|
||||||
url = '{}/precompiled-preview.png{}'.format(
|
if request.args.get('overlay'):
|
||||||
current_app.config['TEMPLATE_PREVIEW_API_HOST'],
|
content = pdf_page
|
||||||
'?hide_notify=true' if page_number == '1' else ''
|
url = '{}/precompiled/overlay.png{}{}'.format(
|
||||||
)
|
current_app.config['TEMPLATE_PREVIEW_API_HOST'],
|
||||||
|
'?invert=1',
|
||||||
|
'&hide_notify=true' if page_number == '1' else ''
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
url = '{}/precompiled-preview.png{}'.format(
|
||||||
|
current_app.config['TEMPLATE_PREVIEW_API_HOST'],
|
||||||
|
'?hide_notify=true' if page_number == '1' else ''
|
||||||
|
)
|
||||||
|
|
||||||
content = _get_png_preview(url, content, notification.id, json=False)
|
content = _get_png_preview(url, content, notification.id, json=False)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1098,12 +1098,18 @@ def test_preview_letter_template_precompiled_s3_error(
|
|||||||
"when calling the GetObject operation: Unauthorized".format(notification.id)
|
"when calling the GetObject operation: Unauthorized".format(notification.id)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"post_url, overlay",
|
||||||
|
[('precompiled-preview.png', None), ('precompiled/overlay.png?invert=1', 1)]
|
||||||
|
)
|
||||||
def test_preview_letter_template_precompiled_png_file_type(
|
def test_preview_letter_template_precompiled_png_file_type(
|
||||||
notify_api,
|
notify_api,
|
||||||
client,
|
client,
|
||||||
admin_request,
|
admin_request,
|
||||||
sample_service,
|
sample_service,
|
||||||
mocker
|
mocker,
|
||||||
|
post_url,
|
||||||
|
overlay
|
||||||
):
|
):
|
||||||
|
|
||||||
template = create_template(sample_service,
|
template = create_template(sample_service,
|
||||||
@@ -1128,7 +1134,7 @@ def test_preview_letter_template_precompiled_png_file_type(
|
|||||||
mocker.patch('app.template.rest.extract_page_from_pdf', return_value=pdf_content)
|
mocker.patch('app.template.rest.extract_page_from_pdf', return_value=pdf_content)
|
||||||
|
|
||||||
mock_post = request_mock.post(
|
mock_post = request_mock.post(
|
||||||
'http://localhost/notifications-template-preview/precompiled-preview.png',
|
'http://localhost/notifications-template-preview/{}'.format(post_url),
|
||||||
content=png_content,
|
content=png_content,
|
||||||
headers={'X-pdf-page-count': '1'},
|
headers={'X-pdf-page-count': '1'},
|
||||||
status_code=200
|
status_code=200
|
||||||
@@ -1138,7 +1144,8 @@ def test_preview_letter_template_precompiled_png_file_type(
|
|||||||
'template.preview_letter_template_by_notification_id',
|
'template.preview_letter_template_by_notification_id',
|
||||||
service_id=notification.service_id,
|
service_id=notification.service_id,
|
||||||
notification_id=notification.id,
|
notification_id=notification.id,
|
||||||
file_type='png'
|
file_type='png',
|
||||||
|
overlay=overlay,
|
||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
|
|||||||
Reference in New Issue
Block a user