Skip to content

Commit

Permalink
Fixed the template uri for the post notification responses.
Browse files Browse the repository at this point in the history
It was optimistic to think the v2 templates would be complete.
  • Loading branch information
Rebecca Law committed Jan 4, 2017
1 parent 7f9111f commit bbdbb90
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
16 changes: 10 additions & 6 deletions app/v2/notifications/notification_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,19 @@
}


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,
Expand All @@ -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))
}
12 changes: 7 additions & 5 deletions app/v2/notifications/post_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down
8 changes: 6 additions & 2 deletions tests/app/v2/notifications/test_post_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down

0 comments on commit bbdbb90

Please sign in to comment.