diff --git a/app/v2/notifications/notification_schemas.py b/app/v2/notifications/notification_schemas.py index c4752ef7b..d75375fcc 100644 --- a/app/v2/notifications/notification_schemas.py +++ b/app/v2/notifications/notification_schemas.py @@ -1,5 +1,6 @@ from datetime import datetime +from app import DATETIME_FORMAT from app.models import NOTIFICATION_STATUS_TYPES, TEMPLATE_TYPES 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, url_root=url_root, 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, url_root=url_root, 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 } diff --git a/tests/app/v2/notifications/test_post_notifications.py b/tests/app/v2/notifications/test_post_notifications.py index 6ead0aeb5..4a6abbb63 100644 --- a/tests/app/v2/notifications/test_post_notifications.py +++ b/tests/app/v2/notifications/test_post_notifications.py @@ -1,6 +1,8 @@ import uuid import pytest from flask import json + +from app import DATETIME_FORMAT from app.models import Notification, ScheduledNotification from app.v2.errors import RateLimitError 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 -@pytest.mark.parametrize("type", ["sms", "email"]) -def test_post_notification_with_scheduled_for(client, sample_template, sample_email_template, type): - if type == 'sms': - data = { - 'phone_number': '+(44) 77009-00855', - 'template_id': str(sample_template.id), - 'scheduled_for': '2017-05-14 15:00:00' - } - else: - data = { - 'email_address': 'jack@blah.com', - 'template_id': str(sample_email_template.id), - 'scheduled_for': '2017-05-14 15:00:00' - } +@pytest.mark.parametrize("notification_type, key_send_to, send_to", + [("sms", "phone_number", "07700 900 855"), + ("email", "email_address", "sample@email.com")]) +def test_post_notification_with_scheduled_for(client, sample_template, sample_email_template, + notification_type, key_send_to, send_to): + data = { + key_send_to: send_to, + 'template_id': str(sample_email_template.id) if notification_type == 'email' else str(sample_template.id), + 'scheduled_for': '2017-05-14 15:00:00' + } 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), headers=[('Content-Type', 'application/json'), auth_header]) 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() assert len(scheduled_notification) == 1 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)