Refactor to re-use existing contract-dependent method

This commit is contained in:
Imdad Ahad
2016-09-14 10:25:09 +01:00
parent 9df24b39ce
commit d4b0f68a69
2 changed files with 11 additions and 26 deletions

View File

@@ -260,9 +260,10 @@ def send_notification(notification_type):
status_code=400
)
notification_id = create_uuid()
notification.update({"template_version": template.version})
if not _simulated_recipient(notification['to'], notification_type):
notification_id = create_uuid()
notification.update({"template_version": template.version})
persist_notification(
service,
notification_id,
@@ -273,16 +274,12 @@ def send_notification(notification_type):
api_user.key_type
)
return jsonify(
data=get_notification_return_data(
notification_id,
notification,
template_object)
), 201
else:
return jsonify(
data=_get_simulated_recipient_response_data(template_object)
), 200
return jsonify(
data=get_notification_return_data(
notification_id,
notification,
template_object)
), 201
def get_notification_return_data(notification_id, notification, template):
@@ -314,18 +311,6 @@ def _simulated_recipient(to_address, notification_type):
else to_address in current_app.config['SIMULATED_EMAIL_ADDRESSES'])
def _get_simulated_recipient_response_data(template_object):
response_data = {
'body': template_object.replaced,
'template_version': template_object._template['version']
}
if template_object._template['template_type'] == 'email':
response_data.update({'subject': template_object.replaced_subject})
return response_data
def persist_notification(
service,
notification_id,