Fixed the template uri for the post notification responses.

It was optimistic to think the v2 templates would be complete.
This commit is contained in:
Rebecca Law
2017-01-04 11:22:50 +00:00
parent 7f9111fd90
commit bbdbb9079e
3 changed files with 23 additions and 13 deletions

View File

@@ -187,17 +187,19 @@ post_email_response = {
}
def create_post_sms_response_from_notification(notification, body, from_number, url_root):
def create_post_sms_response_from_notification(notification, body, from_number, url_root, service_id):
return {"id": notification.id,
"reference": notification.client_reference,
"content": {'body': body,
'from_number': from_number},
"uri": "{}v2/notifications/{}".format(url_root, str(notification.id)),
"template": __create_template_from_notification(notification=notification, url_root=url_root)
"template": __create_template_from_notification(notification=notification,
url_root=url_root,
service_id=service_id)
}
def create_post_email_response_from_notification(notification, content, subject, email_from, url_root):
def create_post_email_response_from_notification(notification, content, subject, email_from, url_root, service_id):
return {
"id": notification.id,
"reference": notification.client_reference,
@@ -207,13 +209,15 @@ def create_post_email_response_from_notification(notification, content, subject,
"subject": subject
},
"uri": "{}v2/notifications/{}".format(url_root, str(notification.id)),
"template": __create_template_from_notification(notification=notification, url_root=url_root)
"template": __create_template_from_notification(notification=notification,
url_root=url_root,
service_id=service_id)
}
def __create_template_from_notification(notification, url_root):
def __create_template_from_notification(notification, url_root, service_id):
return {
"id": notification.template_id,
"version": notification.template_version,
"uri": "{}v2/templates/{}".format(url_root, str(notification.template_id))
"uri": "{}services/{}/templates/{}".format(url_root, str(service_id), str(notification.template_id))
}

View File

@@ -41,10 +41,11 @@ def post_sms_notification():
reference=form.get('reference'))
send_notification_to_queue(notification, service.research_mode)
sms_sender = service.sms_sender if service.sms_sender else current_app.config.get('FROM_NUMBER')
resp = create_post_sms_response_from_notification(notification,
str(template_with_content),
sms_sender,
request.url_root)
resp = create_post_sms_response_from_notification(notification=notification,
body=str(template_with_content),
from_number=sms_sender,
url_root=request.url_root,
service_id=service.id)
return jsonify(resp), 201
@@ -73,7 +74,8 @@ def post_email_notification():
content=str(template_with_content),
subject=template_with_content.subject,
email_from=service.email_from,
url_root=request.url_root)
url_root=request.url_root,
service_id=service.id)
return jsonify(resp), 201

View File

@@ -37,7 +37,9 @@ def test_post_sms_notification_returns_201(notify_api, sample_template_with_plac
assert 'v2/notifications/{}'.format(notification_id) in resp_json['uri']
assert resp_json['template']['id'] == str(sample_template_with_placeholders.id)
assert resp_json['template']['version'] == sample_template_with_placeholders.version
assert 'v2/templates/{}'.format(sample_template_with_placeholders.id) in resp_json['template']['uri']
assert 'services/{}/templates/{}'.format(sample_template_with_placeholders.service_id,
sample_template_with_placeholders.id) \
in resp_json['template']['uri']
assert mocked.called
@@ -137,7 +139,9 @@ def test_post_email_notification_returns_201(client, sample_email_template_with_
assert 'v2/notifications/{}'.format(notification.id) in resp_json['uri']
assert resp_json['template']['id'] == str(sample_email_template_with_placeholders.id)
assert resp_json['template']['version'] == sample_email_template_with_placeholders.version
assert 'v2/templates/{}'.format(sample_email_template_with_placeholders.id) in resp_json['template']['uri']
assert 'services/{}/templates/{}'.format(str(sample_email_template_with_placeholders.service_id),
str(sample_email_template_with_placeholders.id)) \
in resp_json['template']['uri']
assert mocked.called