Call overlaid preview for precompiled letters that fail validation

Also test precompiled letter preview with overlay
This commit is contained in:
Pea Tyczynska
2019-04-04 12:07:08 +01:00
parent 193ff8548c
commit 2f52a8fd64
2 changed files with 22 additions and 7 deletions

View File

@@ -249,6 +249,14 @@ def preview_letter_template_by_notification_id(service_id, notification_id, file
status_code=500
)
if request.args.get('overlay'):
content = pdf_page
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 ''

View File

@@ -1098,12 +1098,18 @@ def test_preview_letter_template_precompiled_s3_error(
"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(
notify_api,
client,
admin_request,
sample_service,
mocker
mocker,
post_url,
overlay
):
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)
mock_post = request_mock.post(
'http://localhost/notifications-template-preview/precompiled-preview.png',
'http://localhost/notifications-template-preview/{}'.format(post_url),
content=png_content,
headers={'X-pdf-page-count': '1'},
status_code=200
@@ -1138,7 +1144,8 @@ def test_preview_letter_template_precompiled_png_file_type(
'template.preview_letter_template_by_notification_id',
service_id=notification.service_id,
notification_id=notification.id,
file_type='png'
file_type='png',
overlay=overlay,
)
with pytest.raises(ValueError):