mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 18:37:33 -04:00
WIP refactor preview pdf
This commit is contained in:
@@ -90,8 +90,6 @@ def view_notification(service_id, notification_id):
|
|||||||
@user_has_permissions('view_activity', admin_override=True)
|
@user_has_permissions('view_activity', admin_override=True)
|
||||||
def view_letter_notification_as_preview(service_id, notification_id, filetype):
|
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'):
|
if filetype not in ('pdf', 'png'):
|
||||||
abort(404)
|
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(
|
preview = notification_api_client.get_notification_letter_preview(
|
||||||
service_id,
|
service_id,
|
||||||
template.id,
|
|
||||||
notification_id,
|
notification_id,
|
||||||
filetype,
|
filetype,
|
||||||
page=request.args.get('page')
|
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/<service_id>/notification/<notification_id>.json")
|
@main.route("/services/<service_id>/notification/<notification_id>.json")
|
||||||
|
|||||||
@@ -79,11 +79,10 @@ class NotificationApiClient(NotifyAdminAPIClient):
|
|||||||
notification['status'] = 'accepted'
|
notification['status'] = 'accepted'
|
||||||
return notifications
|
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,
|
service_id,
|
||||||
template_id,
|
|
||||||
notification_id,
|
notification_id,
|
||||||
file_type,
|
file_type,
|
||||||
'?page={}'.format(page) if page else ''
|
'?page={}'.format(page) if page else ''
|
||||||
|
|||||||
@@ -163,9 +163,14 @@ 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')
|
||||||
|
|
||||||
mocked_preview = mocker.patch(
|
import base64
|
||||||
'app.main.views.templates.TemplatePreview.from_utils_template',
|
mocked_api_client = mocker.patch(
|
||||||
return_value='foo'
|
'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(
|
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.status_code == 200
|
||||||
assert response.get_data(as_text=True) == 'foo'
|
assert response.get_data(as_text=True) == 'foo'
|
||||||
assert isinstance(mocked_preview.call_args[0][0], LetterImageTemplate)
|
assert mocked_api_client.called
|
||||||
assert mocked_preview.call_args[0][1] == filetype
|
|
||||||
|
|
||||||
|
|
||||||
def test_should_404_for_unknown_extension(
|
def test_should_404_for_unknown_extension(
|
||||||
|
|||||||
Reference in New Issue
Block a user