From 383dee3bb2c9918a72835601937b6cb42db0dfb1 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Wed, 24 May 2017 14:52:32 +0100 Subject: [PATCH] Updated the serialization of Notification.scheduled_for to include minutes. --- app/models.py | 7 ++++--- tests/app/celery/test_scheduled_tasks.py | 6 +++--- tests/app/conftest.py | 2 +- tests/app/dao/test_notification_dao.py | 15 ++++++++------- tests/app/test_utils.py | 6 +++--- .../v2/notifications/test_get_notifications.py | 10 +++++----- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/models.py b/app/models.py index 76fa31c91..a85972664 100644 --- a/app/models.py +++ b/app/models.py @@ -30,7 +30,7 @@ from app import ( ) from app.history_meta import Versioned -from app.utils import convert_utc_time_in_bst +from app.utils import convert_utc_time_in_bst, convert_bst_to_utc SMS_TYPE = 'sms' EMAIL_TYPE = 'email' @@ -890,8 +890,9 @@ class Notification(db.Model): "created_at": self.created_at.strftime(DATETIME_FORMAT), "sent_at": self.sent_at.strftime(DATETIME_FORMAT) if self.sent_at else None, "completed_at": self.completed_at(), - "scheduled_for": self.scheduled_notification.scheduled_for.strftime( - "%Y-%m-%d %H") if self.scheduled_notification else None + "scheduled_for": convert_bst_to_utc(self.scheduled_notification.scheduled_for + ).strftime( + "%Y-%m-%d %H:%M") if self.scheduled_notification else None } return serialized diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index af8ac54d5..538475b6e 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -424,13 +424,13 @@ def test_should_send_all_scheduled_notifications_to_deliver_queue(notify_db, sample_template, mocker): mocked = mocker.patch('app.celery.provider_tasks.deliver_sms') message_to_deliver = sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, - template=sample_template, scheduled_for="2017-05-01 13") + template=sample_template, scheduled_for="2017-05-01 13:15") sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, - template=sample_template, scheduled_for="2017-05-01 10", status='delivered') + template=sample_template, scheduled_for="2017-05-01 10:15", status='delivered') sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, template=sample_template) sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, - template=sample_template, scheduled_for="2017-05-01 14") + template=sample_template, scheduled_for="2017-05-01 14:15") scheduled_notifications = dao_get_scheduled_notifications() assert len(scheduled_notifications) == 1 diff --git a/tests/app/conftest.py b/tests/app/conftest.py index 032a134fc..b7ca092ba 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -494,7 +494,7 @@ def sample_notification( scheduled_notification = ScheduledNotification(id=uuid.uuid4(), notification_id=notification.id, scheduled_for=datetime.strptime(scheduled_for, - "%Y-%m-%d %H")) + "%Y-%m-%d %H:%M")) if status != 'created': scheduled_notification.pending = False db.session.add(scheduled_notification) diff --git a/tests/app/dao/test_notification_dao.py b/tests/app/dao/test_notification_dao.py index c8e86889c..6d1842da1 100644 --- a/tests/app/dao/test_notification_dao.py +++ b/tests/app/dao/test_notification_dao.py @@ -720,7 +720,7 @@ def test_save_notification_with_no_job(sample_template, mmg_provider): def test_get_notification_by_id(notify_db, notify_db_session, sample_template): notification = sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, template=sample_template, - scheduled_for='2017-05-05 14', + scheduled_for='2017-05-05 14:15', status='created') notification_from_db = get_notification_with_personalisation( sample_template.service.id, @@ -728,7 +728,7 @@ def test_get_notification_by_id(notify_db, notify_db_session, sample_template): key_type=None ) assert notification == notification_from_db - assert notification_from_db.scheduled_notification.scheduled_for == datetime(2017, 5, 5, 14) + assert notification_from_db.scheduled_notification.scheduled_for == datetime(2017, 5, 5, 14, 15) def test_get_notifications_by_reference(notify_db, notify_db_session, sample_service): @@ -1760,20 +1760,21 @@ def test_dao_get_notifications_by_to_field_search_ignores_spaces(sample_template def test_dao_created_scheduled_notification(sample_notification): scheduled_notification = ScheduledNotification(notification_id=sample_notification.id, - scheduled_for=datetime.strptime("2017-01-05 14", "%Y-%m-%d %H")) + scheduled_for=datetime.strptime("2017-01-05 14:15", + "%Y-%m-%d %H:%M")) dao_created_scheduled_notification(scheduled_notification) saved_notification = ScheduledNotification.query.all() assert len(saved_notification) == 1 assert saved_notification[0].notification_id == sample_notification.id - assert saved_notification[0].scheduled_for == datetime(2017, 1, 5, 14) + assert saved_notification[0].scheduled_for == datetime(2017, 1, 5, 14, 15) def test_dao_get_scheduled_notifications(notify_db, notify_db_session, sample_template): notification_1 = sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, - template=sample_template, scheduled_for='2017-05-05 14', + template=sample_template, scheduled_for='2017-05-05 14:15', status='created') sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, - template=sample_template, scheduled_for='2017-05-04 14', status='delivered') + template=sample_template, scheduled_for='2017-05-04 14:15', status='delivered') sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, template=sample_template, status='created') scheduled_notifications = dao_get_scheduled_notifications() @@ -1784,7 +1785,7 @@ def test_dao_get_scheduled_notifications(notify_db, notify_db_session, sample_te def test_set_scheduled_notification_to_processed(notify_db, notify_db_session, sample_template): notification_1 = sample_notification(notify_db=notify_db, notify_db_session=notify_db_session, - template=sample_template, scheduled_for='2017-05-05 14', + template=sample_template, scheduled_for='2017-05-05 14:15', status='created') scheduled_notifications = dao_get_scheduled_notifications() assert len(scheduled_notifications) == 1 diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index 7bb8360af..3b795549f 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -40,7 +40,7 @@ def test_get_utc_in_bst_returns_expected_date(date, expected_date): def test_convert_bst_to_utc(): - bst = "2017-05-12 13" - bst_datetime = datetime.strptime(bst, "%Y-%m-%d %H") + bst = "2017-05-12 13:15" + bst_datetime = datetime.strptime(bst, "%Y-%m-%d %H:%M") utc = convert_bst_to_utc(bst_datetime) - assert utc == datetime(2017, 5, 12, 12, 0) + assert utc == datetime(2017, 5, 12, 12, 15) diff --git a/tests/app/v2/notifications/test_get_notifications.py b/tests/app/v2/notifications/test_get_notifications.py index 30a35b5aa..2566cbc7d 100644 --- a/tests/app/v2/notifications/test_get_notifications.py +++ b/tests/app/v2/notifications/test_get_notifications.py @@ -20,12 +20,12 @@ def test_get_notification_by_id_returns_200( ): sample_notification = create_sample_notification( notify_db, notify_db_session, billable_units=billable_units, sent_by=provider, - scheduled_for="2017-05-12 14" + scheduled_for="2017-05-12 15:15" ) another = create_sample_notification( notify_db, notify_db_session, billable_units=billable_units, sent_by=provider, - scheduled_for="2017-06-12 14" + scheduled_for="2017-06-12 15:15" ) auth_header = create_authorization_header(service_id=sample_notification.service_id) response = client.get( @@ -63,7 +63,7 @@ def test_get_notification_by_id_returns_200( "subject": None, 'sent_at': sample_notification.sent_at, 'completed_at': sample_notification.completed_at(), - 'scheduled_for': '2017-05-12 14' + 'scheduled_for': '2017-05-12 14:15' } assert json_response == expected_response @@ -139,7 +139,7 @@ def test_get_notification_by_reference_returns_200(client, notify_db, notify_db_ def test_get_notifications_returns_scheduled_for(client, notify_db, notify_db_session): sample_notification_with_reference = create_sample_notification( - notify_db, notify_db_session, client_reference='some-client-reference', scheduled_for='2017-05-23 16') + notify_db, notify_db_session, client_reference='some-client-reference', scheduled_for='2017-05-23 17:15') auth_header = create_authorization_header(service_id=sample_notification_with_reference.service_id) response = client.get( @@ -153,7 +153,7 @@ def test_get_notifications_returns_scheduled_for(client, notify_db, notify_db_se assert len(json_response['notifications']) == 1 assert json_response['notifications'][0]['id'] == str(sample_notification_with_reference.id) - assert json_response['notifications'][0]['scheduled_for'] == "2017-05-23 16" + assert json_response['notifications'][0]['scheduled_for'] == "2017-05-23 16:15" def test_get_notification_by_reference_nonexistent_reference_returns_no_notifications(client, sample_service):