diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index 99889e238..6dac7e084 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -3,6 +3,7 @@ import json import random import string from datetime import datetime, timedelta +from json import JSONDecodeError import botocore import pytest @@ -828,7 +829,7 @@ def test_preview_letter_template_by_id_valid_file_type( with requests_mock.Mocker() as request_mock: content = b'\x00\x01' - request_mock.post( + mock_post = request_mock.post( 'http://localhost/notifications-template-preview/preview.pdf', content=content, headers={'X-pdf-page-count': '1'}, @@ -842,6 +843,7 @@ def test_preview_letter_template_by_id_valid_file_type( file_type='pdf' ) + assert mock_post.last_request.json() assert base64.b64decode(resp['content']) == content @@ -859,7 +861,7 @@ def test_preview_letter_template_by_id_template_preview_500( with requests_mock.Mocker() as request_mock: content = b'\x00\x01' - request_mock.post( + mock_post = request_mock.post( 'http://localhost/notifications-template-preview/preview.pdf', content=content, headers={'X-pdf-page-count': '1'}, @@ -874,11 +876,11 @@ def test_preview_letter_template_by_id_template_preview_500( _expected_status=500 ) + assert mock_post.last_request.json() assert 'Status code: 404' in resp['message'] assert 'Error generating preview letter for {}'.format(sample_letter_notification.id) in resp['message'] - def test_preview_letter_template_precompiled_pdf_file_type( notify_api, client, @@ -980,7 +982,7 @@ def test_preview_letter_template_precompiled_png_file_type( mock_get_letter_pdf = mocker.patch('app.template.rest.get_letter_pdf', return_value=pdf_content) - request_mock.post( + mock_post = request_mock.post( 'http://localhost/notifications-template-preview/precompiled-preview.png', content=png_content, headers={'X-pdf-page-count': '1'}, @@ -994,6 +996,8 @@ def test_preview_letter_template_precompiled_png_file_type( file_type='png' ) + with pytest.raises(JSONDecodeError): + mock_post.last_request.json() assert mock_get_letter_pdf.called_once_with(notification) assert base64.b64decode(resp['content']) == png_content @@ -1025,7 +1029,7 @@ def test_preview_letter_template_precompiled_png_template_preview_500_error( mocker.patch('app.template.rest.get_letter_pdf', return_value=pdf_content) - request_mock.post( + mock_post = request_mock.post( 'http://localhost/notifications-template-preview/precompiled-preview.png', content=png_content, headers={'X-pdf-page-count': '1'}, @@ -1041,6 +1045,9 @@ def test_preview_letter_template_precompiled_png_template_preview_500_error( ) + with pytest.raises(JSONDecodeError): + mock_post.last_request.json() + def test_preview_letter_template_precompiled_png_template_preview_400_error( notify_api, @@ -1069,7 +1076,7 @@ def test_preview_letter_template_precompiled_png_template_preview_400_error( mocker.patch('app.template.rest.get_letter_pdf', return_value=pdf_content) - request_mock.post( + mock_post = request_mock.post( 'http://localhost/notifications-template-preview/precompiled-preview.png', content=png_content, headers={'X-pdf-page-count': '1'}, @@ -1082,5 +1089,7 @@ def test_preview_letter_template_precompiled_png_template_preview_400_error( notification_id=notification.id, file_type='png', _expected_status=500 - ) + + with pytest.raises(JSONDecodeError): + mock_post.last_request.json()