From 4abbb7137a3f56378a29f98d1205040cb8bd18a8 Mon Sep 17 00:00:00 2001 From: Toby Lorne Date: Tue, 2 Apr 2019 08:25:09 +0100 Subject: [PATCH] Fix sending of performance platform The pp client converts to UTC using the convert_utc_to_bst notify util. This requires a datatime not a date, pass it a datetime, and add an assertion in an existing test. I didn't want to use the midnight conversion util in the test. Signed-off-by: Toby Lorne --- .../total_sent_notifications.py | 5 ++++- .../test_total_sent_notifications.py | 20 ++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/performance_platform/total_sent_notifications.py b/app/performance_platform/total_sent_notifications.py index 6dc1d039a..324010015 100644 --- a/app/performance_platform/total_sent_notifications.py +++ b/app/performance_platform/total_sent_notifications.py @@ -1,5 +1,6 @@ from app import performance_platform_client from app.dao.fact_notification_status_dao import get_total_sent_notifications_for_day_and_type +from app.utils import get_london_midnight_in_utc def send_total_notifications_sent_for_day_stats(date, notification_type, count): @@ -19,8 +20,10 @@ def get_total_sent_notifications_for_day(day): sms_count = get_total_sent_notifications_for_day_and_type(day, 'sms') letter_count = get_total_sent_notifications_for_day_and_type(day, 'letter') + start_date = get_london_midnight_in_utc(day) + return { - "start_date": day, + "start_date": start_date, "email": { "count": email_count }, diff --git a/tests/app/performance_platform/test_total_sent_notifications.py b/tests/app/performance_platform/test_total_sent_notifications.py index 0945903cc..c291a3794 100644 --- a/tests/app/performance_platform/test_total_sent_notifications.py +++ b/tests/app/performance_platform/test_total_sent_notifications.py @@ -53,15 +53,11 @@ def test_get_total_sent_notifications_yesterday_returns_expected_totals_dict(sam total_count_dict = get_total_sent_notifications_for_day(yesterday) - assert total_count_dict == { - "start_date": yesterday, - "email": { - "count": 3 - }, - "sms": { - "count": 2 - }, - "letter": { - "count": 1 - } - } + assert total_count_dict["email"] == {"count": 3} + assert total_count_dict["sms"] == {"count": 2} + assert total_count_dict["letter"] == {"count": 1} + + # Should return a time around midnight depending on timezones + expected_start = datetime.combine(yesterday, datetime.min.time()) + time_diff = abs(expected_start - total_count_dict["start_date"]) + assert time_diff <= timedelta(minutes=60)