diff --git a/app/v2/notifications/notification_schemas.py b/app/v2/notifications/notification_schemas.py index 7675e035b..240d41324 100644 --- a/app/v2/notifications/notification_schemas.py +++ b/app/v2/notifications/notification_schemas.py @@ -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)) } diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index bef56e31a..524fd6a99 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -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 diff --git a/tests/app/v2/notifications/test_post_notifications.py b/tests/app/v2/notifications/test_post_notifications.py index 232fdd983..34aa043bb 100644 --- a/tests/app/v2/notifications/test_post_notifications.py +++ b/tests/app/v2/notifications/test_post_notifications.py @@ -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