Return the scheduled_for datetime in the DATETIME_FORMAT from the post_notification

This commit is contained in:
Rebecca Law
2017-05-16 09:57:58 +01:00
parent f0e2713bef
commit a6529d2723
2 changed files with 19 additions and 18 deletions

View File

@@ -1,5 +1,6 @@
from datetime import datetime from datetime import datetime
from app import DATETIME_FORMAT
from app.models import NOTIFICATION_STATUS_TYPES, TEMPLATE_TYPES from app.models import NOTIFICATION_STATUS_TYPES, TEMPLATE_TYPES
from app.schema_validation.definitions import (uuid, personalisation) from app.schema_validation.definitions import (uuid, personalisation)
@@ -203,7 +204,8 @@ def create_post_sms_response_from_notification(notification, body, from_number,
"template": __create_template_from_notification(notification=notification, "template": __create_template_from_notification(notification=notification,
url_root=url_root, url_root=url_root,
service_id=service_id), service_id=service_id),
"scheduled_for": scheduled_for "scheduled_for": datetime.strptime(scheduled_for,
"%Y-%m-%d %H:%M:%S").strftime(DATETIME_FORMAT) if scheduled_for else None
} }
@@ -221,7 +223,8 @@ def create_post_email_response_from_notification(notification, content, subject,
"template": __create_template_from_notification(notification=notification, "template": __create_template_from_notification(notification=notification,
url_root=url_root, url_root=url_root,
service_id=service_id), service_id=service_id),
"scheduled_for": scheduled_for "scheduled_for": datetime.strptime(scheduled_for,
"%Y-%m-%d %H:%M:%S").strftime(DATETIME_FORMAT) if scheduled_for else None
} }

View File

@@ -1,6 +1,8 @@
import uuid import uuid
import pytest import pytest
from flask import json from flask import json
from app import DATETIME_FORMAT
from app.models import Notification, ScheduledNotification from app.models import Notification, ScheduledNotification
from app.v2.errors import RateLimitError from app.v2.errors import RateLimitError
from tests import create_authorization_header from tests import create_authorization_header
@@ -348,23 +350,19 @@ def test_post_sms_should_persist_supplied_sms_number(client, sample_template_wit
assert mocked.called assert mocked.called
@pytest.mark.parametrize("type", ["sms", "email"]) @pytest.mark.parametrize("notification_type, key_send_to, send_to",
def test_post_notification_with_scheduled_for(client, sample_template, sample_email_template, type): [("sms", "phone_number", "07700 900 855"),
if type == 'sms': ("email", "email_address", "sample@email.com")])
data = { def test_post_notification_with_scheduled_for(client, sample_template, sample_email_template,
'phone_number': '+(44) 77009-00855', notification_type, key_send_to, send_to):
'template_id': str(sample_template.id), data = {
'scheduled_for': '2017-05-14 15:00:00' key_send_to: send_to,
} 'template_id': str(sample_email_template.id) if notification_type == 'email' else str(sample_template.id),
else: 'scheduled_for': '2017-05-14 15:00:00'
data = { }
'email_address': 'jack@blah.com',
'template_id': str(sample_email_template.id),
'scheduled_for': '2017-05-14 15:00:00'
}
auth_header = create_authorization_header(service_id=sample_template.service_id) auth_header = create_authorization_header(service_id=sample_template.service_id)
response = client.post('/v2/notifications/{}'.format(type), response = client.post('/v2/notifications/{}'.format(notification_type),
data=json.dumps(data), data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header]) headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 201 assert response.status_code == 201
@@ -372,4 +370,4 @@ def test_post_notification_with_scheduled_for(client, sample_template, sample_em
scheduled_notification = ScheduledNotification.query.all() scheduled_notification = ScheduledNotification.query.all()
assert len(scheduled_notification) == 1 assert len(scheduled_notification) == 1
assert resp_json["id"] == str(scheduled_notification[0].notification_id) assert resp_json["id"] == str(scheduled_notification[0].notification_id)
assert resp_json["scheduled_for"] == str(scheduled_notification[0].scheduled_for) assert resp_json["scheduled_for"] == scheduled_notification[0].scheduled_for.strftime(DATETIME_FORMAT)