Merge pull request #2662 from alphagov/utils-bump

Utils bump
This commit is contained in:
Leo Hemsted
2019-11-19 10:55:07 +00:00
committed by Rebecca Law
11 changed files with 150 additions and 41 deletions

View File

@@ -62,10 +62,11 @@ from app.v2.notifications.notification_schemas import (
@v2_notification_blueprint.route('/{}'.format(LETTER_TYPE), methods=['POST'])
def post_precompiled_letter_notification():
if 'content' not in (request.get_json() or {}):
request_json = get_valid_json()
if 'content' not in (request_json or {}):
return post_notification(LETTER_TYPE)
form = validate(request.get_json(), post_precompiled_letter_request)
form = validate(request_json, post_precompiled_letter_request)
# Check permission to send letters
check_service_has_permission(LETTER_TYPE, authenticated_service.permissions)
@@ -99,11 +100,7 @@ def post_precompiled_letter_notification():
@v2_notification_blueprint.route('/<notification_type>', methods=['POST'])
def post_notification(notification_type):
try:
request_json = request.get_json()
except BadRequest as e:
raise BadRequestError(message="Error decoding arguments: {}".format(e.description),
status_code=400)
request_json = get_valid_json()
if notification_type == EMAIL_TYPE:
form = validate(request_json, post_email_request)
@@ -176,6 +173,15 @@ def post_notification(notification_type):
return jsonify(resp), 201
def get_valid_json():
try:
request_json = request.get_json(force=True)
except BadRequest:
raise BadRequestError(message="Invalid JSON supplied in POST data",
status_code=400)
return request_json
def process_sms_or_email_notification(*, form, notification_type, api_key, template, service, reply_to_text=None):
form_send_to = form['email_address'] if notification_type == EMAIL_TYPE else form['phone_number']

View File

@@ -11,6 +11,9 @@ from app.v2.template.template_schemas import post_template_preview_request, crea
@v2_template_blueprint.route("/<template_id>/preview", methods=['POST'])
def post_template_preview(template_id):
if not request.content_type or request.content_type != 'application/json':
raise BadRequestError(message="Content-Type header is not set to application/json.",
status_code=400)
_data = request.get_json()
if _data is None:
_data = {}