From 6279169b18593c439641c78858eee77c90c85e69 Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Wed, 28 Feb 2018 14:18:42 +0000 Subject: [PATCH] WIP refactor preview pdf --- app/main/views/notifications.py | 6 ++---- app/notify_client/notification_api_client.py | 5 ++--- tests/app/main/views/test_notifications.py | 14 +++++++++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py index 9aa42a2c0..e9bb3e3ec 100644 --- a/app/main/views/notifications.py +++ b/app/main/views/notifications.py @@ -90,8 +90,6 @@ def view_notification(service_id, notification_id): @user_has_permissions('view_activity', admin_override=True) def view_letter_notification_as_preview(service_id, notification_id, filetype): - print("\n\nview_letter_notification_as_preview\n\n") - if filetype not in ('pdf', 'png'): abort(404) @@ -113,13 +111,13 @@ def view_letter_notification_as_preview(service_id, notification_id, filetype): preview = notification_api_client.get_notification_letter_preview( service_id, - template.id, notification_id, filetype, page=request.args.get('page') ) - return base64.b64decode(preview['content']), preview['status'], ItemsView(dict(preview['headers'])) + # return base64.b64decode(preview['content']), preview['status'], ItemsView(dict(preview['headers'])) + return base64.b64decode(preview['content']) @main.route("/services//notification/.json") diff --git a/app/notify_client/notification_api_client.py b/app/notify_client/notification_api_client.py index b3ddf51fd..5ace4bfa2 100644 --- a/app/notify_client/notification_api_client.py +++ b/app/notify_client/notification_api_client.py @@ -79,11 +79,10 @@ class NotificationApiClient(NotifyAdminAPIClient): notification['status'] = 'accepted' return notifications - def get_notification_letter_preview(self, service_id, template_id, notification_id, file_type, page=None): + def get_notification_letter_preview(self, service_id, notification_id, file_type, page=None): - get_url = '/service/{}/template/{}/pdf-preview/{}/{}{}'.format( + get_url = '/service/{}/template/preview/{}/{}{}'.format( service_id, - template_id, notification_id, file_type, '?page={}'.format(page) if page else '' diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py index 958c2827d..fb4ac821c 100644 --- a/tests/app/main/views/test_notifications.py +++ b/tests/app/main/views/test_notifications.py @@ -163,9 +163,14 @@ def test_should_show_image_of_letter_notification( mock_get_notification(mocker, fake_uuid, template_type='letter') - mocked_preview = mocker.patch( - 'app.main.views.templates.TemplatePreview.from_utils_template', - return_value='foo' + import base64 + mocked_api_client = mocker.patch( + 'app.notify_client.notification_api_client.NotificationApiClient.get', + return_value={ + 'content': base64.b64encode(b'foo').decode('utf-8'), + 'status': 200, + 'headers': [{'test': 'test', 'test1': 'test1'}] + } ) response = logged_in_client.get(url_for( @@ -177,8 +182,7 @@ def test_should_show_image_of_letter_notification( assert response.status_code == 200 assert response.get_data(as_text=True) == 'foo' - assert isinstance(mocked_preview.call_args[0][0], LetterImageTemplate) - assert mocked_preview.call_args[0][1] == filetype + assert mocked_api_client.called def test_should_404_for_unknown_extension(