Moved the call to retrieve the pdf into the is_precompiled_letter block

as it did not need to be called for standard letters.

Changed the tests to use the mock from get_notification_letter_preview
instead of a generic NotificationApiClient.get. This will hopefully
protect any subsequent changes or calls from not being tested in future.
This commit is contained in:
Richard Chapman
2018-03-09 13:28:16 +00:00
parent e25c6cd3b9
commit 86a474ce8b
2 changed files with 4 additions and 5 deletions

View File

@@ -46,9 +46,8 @@ def view_notification(service_id, notification_id):
notification = notification_api_client.get_notification(service_id, str(notification_id)) notification = notification_api_client.get_notification(service_id, str(notification_id))
notification['template'].update({'reply_to_text': notification['reply_to_text']}) notification['template'].update({'reply_to_text': notification['reply_to_text']})
file_contents = view_letter_notification_as_preview(service_id, notification_id, "pdf")
if notification['template']['is_precompiled_letter']: if notification['template']['is_precompiled_letter']:
file_contents = view_letter_notification_as_preview(service_id, notification_id, "pdf")
page_count = pdf_page_count(io.BytesIO(file_contents)) page_count = pdf_page_count(io.BytesIO(file_contents))
else: else:
page_count = get_page_count_for_letter(notification['template']) page_count = get_page_count_for_letter(notification['template'])

View File

@@ -166,7 +166,7 @@ def test_should_show_image_of_letter_notification(
mock_get_notification(mocker, fake_uuid, template_type='letter') mock_get_notification(mocker, fake_uuid, template_type='letter')
mocker.patch( mocker.patch(
'app.notify_client.notification_api_client.NotificationApiClient.get', 'app.main.views.notifications.notification_api_client.get_notification_letter_preview',
return_value={ return_value={
'content': base64.b64encode(b'foo').decode('utf-8') 'content': base64.b64encode(b'foo').decode('utf-8')
} }
@@ -192,7 +192,7 @@ def test_should_show_preview_error_image_letter_notification_on_preview_error(
mock_get_notification(mocker, fake_uuid, template_type='letter') mock_get_notification(mocker, fake_uuid, template_type='letter')
mocker.patch( mocker.patch(
'app.notify_client.notification_api_client.NotificationApiClient.get', 'app.main.views.notifications.notification_api_client.get_notification_letter_preview',
side_effect=APIError side_effect=APIError
) )
@@ -366,7 +366,7 @@ def test_should_show_image_of_precompiled_letter_notification(
) )
mocker.patch( mocker.patch(
'app.notify_client.notification_api_client.NotificationApiClient.get', 'app.main.views.notifications.notification_api_client.get_notification_letter_preview',
return_value={ return_value={
'content': base64.b64encode(b'foo').decode('utf-8') 'content': base64.b64encode(b'foo').decode('utf-8')
} }