From 751abb4b999dfd4ebab4bda3dda4d5675a2eb048 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 22 May 2017 14:15:35 +0100 Subject: [PATCH] Update dateformat for scheduled_for to include minutes. --- app/notifications/process_notifications.py | 2 +- app/schema_validation/__init__.py | 4 ++-- tests/app/notifications/test_process_notification.py | 4 ++-- tests/app/v2/notifications/test_notification_schemas.py | 4 ++-- tests/app/v2/notifications/test_post_notifications.py | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/notifications/process_notifications.py b/app/notifications/process_notifications.py index 4383858bb..20550be7a 100644 --- a/app/notifications/process_notifications.py +++ b/app/notifications/process_notifications.py @@ -128,7 +128,7 @@ def simulated_recipient(to_address, notification_type): def persist_scheduled_notification(notification_id, scheduled_for): - scheduled_datetime = convert_bst_to_utc(datetime.strptime(scheduled_for, "%Y-%m-%d %H")) + scheduled_datetime = convert_bst_to_utc(datetime.strptime(scheduled_for, "%Y-%m-%d %H:%M")) scheduled_notification = ScheduledNotification(notification_id=notification_id, scheduled_for=scheduled_datetime) dao_created_scheduled_notification(scheduled_notification) diff --git a/app/schema_validation/__init__.py b/app/schema_validation/__init__.py index 4d9d0bc55..b530a17b0 100644 --- a/app/schema_validation/__init__.py +++ b/app/schema_validation/__init__.py @@ -25,10 +25,10 @@ def validate(json_to_validate, schema): def validate_schema_date_with_hour(instance): if isinstance(instance, str): try: - datetime.strptime(instance, "%Y-%m-%d %H") + datetime.strptime(instance, "%Y-%m-%d %H:%M") except ValueError as e: raise ValidationError("datetime format is invalid. Use the format: " - "YYYY-MM-DD HH, for example 2017-05-30 13") + "YYYY-MM-DD HH:MI, for example 2017-05-30 13:15") return True validator = Draft4Validator(schema, format_checker=format_checker) diff --git a/tests/app/notifications/test_process_notification.py b/tests/app/notifications/test_process_notification.py index 56d356842..6df3862a3 100644 --- a/tests/app/notifications/test_process_notification.py +++ b/tests/app/notifications/test_process_notification.py @@ -343,8 +343,8 @@ def test_persist_notification_with_international_info_does_not_store_for_email( def test_persist_scheduled_notification(sample_notification): - persist_scheduled_notification(sample_notification.id, '2017-05-12 14') + persist_scheduled_notification(sample_notification.id, '2017-05-12 14:15') scheduled_notification = ScheduledNotification.query.all() assert len(scheduled_notification) == 1 assert scheduled_notification[0].notification_id == sample_notification.id - assert scheduled_notification[0].scheduled_for == datetime.datetime(2017, 5, 12, 13, 0) + assert scheduled_notification[0].scheduled_for == datetime.datetime(2017, 5, 12, 13, 15) diff --git a/tests/app/v2/notifications/test_notification_schemas.py b/tests/app/v2/notifications/test_notification_schemas.py index 5e0cb354f..90139c7c2 100644 --- a/tests/app/v2/notifications/test_notification_schemas.py +++ b/tests/app/v2/notifications/test_notification_schemas.py @@ -360,7 +360,7 @@ def test_get_notifications_response_with_email_and_phone_number(): def test_post_schema_valid_scheduled_for(schema): j = {"template_id": str(uuid.uuid4()), "email_address": "joe@gmail.com", - "scheduled_for": "2017-05-12 13"} + "scheduled_for": "2017-05-12 13:15"} if schema == post_email_request_schema: j.update({"email_address": "joe@gmail.com"}) else: @@ -385,4 +385,4 @@ def test_post_email_schema_invalid_scheduled_for(invalid_datetime, schema): assert error['status_code'] == 400 assert error['errors'] == [{'error': 'ValidationError', 'message': "scheduled_for datetime format is invalid. Use the format: " - "YYYY-MM-DD HH, for example 2017-05-30 13"}] + "YYYY-MM-DD HH:MI, for example 2017-05-30 13:15"}] diff --git a/tests/app/v2/notifications/test_post_notifications.py b/tests/app/v2/notifications/test_post_notifications.py index e0903ef6b..114e2e8aa 100644 --- a/tests/app/v2/notifications/test_post_notifications.py +++ b/tests/app/v2/notifications/test_post_notifications.py @@ -358,7 +358,7 @@ def test_post_notification_with_scheduled_for(client, sample_template, sample_em 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 14' + 'scheduled_for': '2017-05-14 14:15' } auth_header = create_authorization_header(service_id=sample_template.service_id) @@ -370,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"] == '2017-05-14 14' + assert resp_json["scheduled_for"] == '2017-05-14 14:15'