From 924cec05b4ab1de16a978d1f00f1076f47463101 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Wed, 16 Nov 2016 15:44:16 +0000 Subject: [PATCH] Included reference when persisting the notification. This was already part of the data model. Not included in the send_sms|email task because there is no reference from the job. --- app/notifications/process_notifications.py | 8 +++++--- app/v2/notifications/notification_schemas.py | 2 +- app/v2/notifications/post_notifications.py | 6 ++++-- tests/app/v2/notifications/test_post_notifications.py | 7 ++++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/notifications/process_notifications.py b/app/notifications/process_notifications.py index 5df9e7b36..d76d92521 100644 --- a/app/notifications/process_notifications.py +++ b/app/notifications/process_notifications.py @@ -46,7 +46,8 @@ def persist_notification(template_id, key_type, created_at=None, job_id=None, - job_row_number=None): + job_row_number=None, + reference=None): notification = Notification( template_id=template_id, template_version=template_version, @@ -56,9 +57,10 @@ def persist_notification(template_id, notification_type=notification_type, api_key_id=api_key_id, key_type=key_type, - created_at=created_at if created_at else datetime.utcnow().strftime(DATETIME_FORMAT), + created_at=created_at or datetime.utcnow().strftime(DATETIME_FORMAT), job_id=job_id, - job_row_number=job_row_number + job_row_number=job_row_number, + reference=reference ) dao_create_notification(notification) return notification diff --git a/app/v2/notifications/notification_schemas.py b/app/v2/notifications/notification_schemas.py index 97402a288..42f418567 100644 --- a/app/v2/notifications/notification_schemas.py +++ b/app/v2/notifications/notification_schemas.py @@ -101,7 +101,7 @@ post_email_response = { def create_post_sms_response_from_notification(notification, body, from_number, url_root): return {"id": notification.id, - "reference": None, # not yet implemented + "reference": notification.reference, "content": {'body': body, 'from_number': from_number}, "uri": "{}/v2/notifications/{}".format(url_root, str(notification.id)), diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index b8c15081a..07127b730 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -37,7 +37,8 @@ def post_sms_notification(): personalisation=form.get('personalisation', None), notification_type=SMS_TYPE, api_key_id=api_user.id, - key_type=api_user.key_type) + key_type=api_user.key_type, + reference=form['reference']) send_notification_to_queue(notification, service.research_mode) resp = create_post_sms_response_from_notification(notification, @@ -63,7 +64,8 @@ def post_email_notification(): personalisation=form.get('personalisation', None), notification_type=EMAIL_TYPE, api_key_id=api_user.id, - key_type=api_user.key_type) + key_type=api_user.key_type, + reference=form['reference']) send_notification_to_queue(notification, service.research_mode) diff --git a/tests/app/v2/notifications/test_post_notifications.py b/tests/app/v2/notifications/test_post_notifications.py index c67066387..eb612ea89 100644 --- a/tests/app/v2/notifications/test_post_notifications.py +++ b/tests/app/v2/notifications/test_post_notifications.py @@ -12,7 +12,8 @@ def test_post_sms_notification_returns_201(notify_api, sample_template, mocker): mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') data = { 'phone_number': '+447700900855', - 'template_id': str(sample_template.id) + 'template_id': str(sample_template.id), + 'reference': 'reference_from_client' } auth_header = create_authorization_header(service_id=sample_template.service_id) @@ -27,7 +28,7 @@ def test_post_sms_notification_returns_201(notify_api, sample_template, mocker): assert len(notifications) == 1 notification_id = notifications[0].id assert resp_json['id'] is not None - assert resp_json['reference'] is None + assert resp_json['reference'] == 'reference_from_client' assert resp_json['content']['body'] == sample_template.content assert resp_json['content']['from_number'] == sample_template.service.sms_sender assert 'v2/notifications/{}'.format(notification_id) in resp_json['uri'] @@ -122,7 +123,7 @@ def test_post_email_notification_returns_201(client, sample_email_template, mock assert len(notifications) == 1 notification_id = notifications[0].id assert resp_json['id'] is not None - assert resp_json['reference'] is None + assert resp_json['reference'] == "reference from caller" assert resp_json['content']['body'] == sample_email_template.content assert resp_json['content']['subject'] == sample_email_template.subject assert resp_json['content']['from_email'] == sample_email_template.service.email_from