From 86a474ce8b297f03715b2d34a9f36d29072794c7 Mon Sep 17 00:00:00 2001 From: Richard Chapman Date: Fri, 9 Mar 2018 13:28:16 +0000 Subject: [PATCH] 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. --- app/main/views/notifications.py | 3 +-- tests/app/main/views/test_notifications.py | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py index 3ba0bb706..ca27f94f0 100644 --- a/app/main/views/notifications.py +++ b/app/main/views/notifications.py @@ -46,9 +46,8 @@ def view_notification(service_id, notification_id): notification = notification_api_client.get_notification(service_id, str(notification_id)) 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']: + file_contents = view_letter_notification_as_preview(service_id, notification_id, "pdf") page_count = pdf_page_count(io.BytesIO(file_contents)) else: page_count = get_page_count_for_letter(notification['template']) diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py index a4034f4f6..0adbe6908 100644 --- a/tests/app/main/views/test_notifications.py +++ b/tests/app/main/views/test_notifications.py @@ -166,7 +166,7 @@ def test_should_show_image_of_letter_notification( mock_get_notification(mocker, fake_uuid, template_type='letter') mocker.patch( - 'app.notify_client.notification_api_client.NotificationApiClient.get', + 'app.main.views.notifications.notification_api_client.get_notification_letter_preview', return_value={ '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') mocker.patch( - 'app.notify_client.notification_api_client.NotificationApiClient.get', + 'app.main.views.notifications.notification_api_client.get_notification_letter_preview', side_effect=APIError ) @@ -366,7 +366,7 @@ def test_should_show_image_of_precompiled_letter_notification( ) mocker.patch( - 'app.notify_client.notification_api_client.NotificationApiClient.get', + 'app.main.views.notifications.notification_api_client.get_notification_letter_preview', return_value={ 'content': base64.b64encode(b'foo').decode('utf-8') }