mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-04 13:40:52 -04:00
Added tests to tests for precompiled flow and refactored a little
* Added is_precompiled_letter method to letter/utils.py * Added tests for letter/utils.py * Added tests for the rest endpoint * Moved the Precompiled name to a central location * Added hidden field to the test method to create a template
This commit is contained in:
@@ -150,6 +150,7 @@ class Config(object):
|
||||
CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID = 'eb4d9930-87ab-4aef-9bce-786762687884'
|
||||
SERVICE_NOW_LIVE_TEMPLATE_ID = '618185c6-3636-49cd-b7d2-6f6f5eb3bdde'
|
||||
ORGANISATION_INVITATION_EMAIL_TEMPLATE_ID = '203566f0-d835-47c5-aa06-932439c86573'
|
||||
PRECOMPILED_TEMPLATE_NAME = 'Pre-compiled PDF'
|
||||
|
||||
BROKER_URL = 'sqs://'
|
||||
BROKER_TRANSPORT_OPTIONS = {
|
||||
|
||||
@@ -76,3 +76,7 @@ def get_letter_pdf(notification):
|
||||
file_content = obj.get()["Body"].read()
|
||||
|
||||
return file_content
|
||||
|
||||
|
||||
def is_precompiled_letter(template):
|
||||
return template.hidden and template.name == current_app.config['PRECOMPILED_TEMPLATE_NAME']
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import base64
|
||||
|
||||
import botocore
|
||||
from flask import (
|
||||
Blueprint,
|
||||
current_app,
|
||||
jsonify,
|
||||
request)
|
||||
from requests import post as requests_post
|
||||
from werkzeug.exceptions import abort
|
||||
|
||||
|
||||
from app.dao.notifications_dao import get_notification_by_id
|
||||
from app.dao.templates_dao import (
|
||||
@@ -18,7 +22,7 @@ from app.dao.templates_dao import (
|
||||
dao_get_template_by_id)
|
||||
from notifications_utils.template import SMSMessageTemplate
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.letters.utils import get_letter_pdf
|
||||
from app.letters.utils import get_letter_pdf, is_precompiled_letter
|
||||
from app.models import SMS_TYPE
|
||||
from app.notifications.validators import service_has_permission, check_reply_to
|
||||
from app.schemas import (template_schema, template_history_schema)
|
||||
@@ -196,18 +200,23 @@ def preview_letter_template_by_notification_id(service_id, notification_id, file
|
||||
|
||||
template = dao_get_template_by_id(notification.template_id)
|
||||
|
||||
if template.hidden and template.name == 'Pre-compiled PDF':
|
||||
if is_precompiled_letter(template):
|
||||
|
||||
pdf_file = get_letter_pdf(notification)
|
||||
try:
|
||||
|
||||
pdf_file = get_letter_pdf(notification)
|
||||
|
||||
except botocore.exceptions.ClientError:
|
||||
abort(404)
|
||||
|
||||
content = base64.b64encode(pdf_file).decode('utf-8')
|
||||
|
||||
if file_type == 'png':
|
||||
|
||||
url = '{}//precompiled-preview.png{}'.format(
|
||||
current_app.config['TEMPLATE_PREVIEW_API_HOST'],
|
||||
'?page={}'.format(page) if page else ''
|
||||
)
|
||||
url = '{}/precompiled-preview.png{}'.format(
|
||||
current_app.config['TEMPLATE_PREVIEW_API_HOST'],
|
||||
'?page={}'.format(page) if page else ''
|
||||
)
|
||||
|
||||
resp = requests_post(
|
||||
url,
|
||||
|
||||
Reference in New Issue
Block a user