Refactor the get_midnight functions to return the date in UTC but for the localised time.

So in June when we are in BST June 16, 00:00 BST => June 15 23:00 UTC
This commit is contained in:
Rebecca Law
2017-01-27 15:57:25 +00:00
parent ac1ca608dd
commit c87d0a37f3
6 changed files with 32 additions and 25 deletions

View File

@@ -16,7 +16,7 @@ from app.celery.scheduled_tasks import (
send_daily_performance_stats
)
from app.dao.jobs_dao import dao_get_job_by_id
from app.utils import get_midnight_for_date
from app.utils import get_london_midnight_in_utc
from tests.app.conftest import (
sample_notification as create_sample_notification,
sample_job as create_sample_job,
@@ -211,6 +211,6 @@ def test_send_daily_performance_stats_calls_with_correct_totals(notify_db, notif
send_daily_performance_stats()
perf_mock.assert_has_calls([
call(get_midnight_for_date(yesterday), 'sms', 2, 'day'),
call(get_midnight_for_date(yesterday), 'email', 3, 'day')
call(get_london_midnight_in_utc(yesterday), 'sms', 2, 'day'),
call(get_london_midnight_in_utc(yesterday), 'email', 3, 'day')
])

View File

@@ -1,5 +1,4 @@
from datetime import datetime, timedelta, date
import pytz
import uuid
from functools import partial
@@ -47,7 +46,7 @@ from app.dao.notifications_dao import (
from app.dao.services_dao import dao_update_service
from app.utils import (
get_midnight_for_date,
get_london_midnight_in_utc,
get_midnight_for_day_before
)
@@ -1489,7 +1488,7 @@ def test_get_total_sent_notifications_yesterday_returns_expected_totals_dict(
assert total_count_dict == {
"start_date": get_midnight_for_day_before(datetime.utcnow()),
"end_date": get_midnight_for_date(datetime.utcnow()),
"end_date": get_london_midnight_in_utc(datetime.utcnow()),
"email": {
"count": 3
},

View File

@@ -2,24 +2,24 @@ from datetime import datetime
import pytest
from app.utils import (
get_midnight_for_date,
get_london_midnight_in_utc,
get_midnight_for_day_before
)
@pytest.mark.parametrize('date, expected_date', [
(datetime(2016, 1, 15, 0, 30), datetime(2016, 1, 15, 0, 0)),
(datetime(2016, 1, 15, 0, 0), datetime(2016, 1, 15, 0, 0)),
(datetime(2016, 1, 15, 11, 59), datetime(2016, 1, 15, 0, 0)),
(datetime(2016, 6, 15, 0, 0), datetime(2016, 6, 14, 23, 0)),
(datetime(2016, 9, 15, 11, 59), datetime(2016, 9, 14, 23, 0)),
])
def test_get_midnight_for_today_returns_expected_date(date, expected_date):
assert get_midnight_for_date(date) == expected_date
def test_get_london_midnight_in_utc_returns_expected_date(date, expected_date):
assert get_london_midnight_in_utc(date) == expected_date
@pytest.mark.parametrize('date, expected_date', [
(datetime(2016, 1, 15, 0, 30), datetime(2016, 1, 14, 0, 0)),
(datetime(2016, 1, 15, 0, 0), datetime(2016, 1, 14, 0, 0)),
(datetime(2016, 1, 15, 11, 59), datetime(2016, 1, 14, 0, 0)),
(datetime(2016, 7, 15, 0, 0), datetime(2016, 7, 13, 23, 0)),
(datetime(2016, 8, 23, 11, 59), datetime(2016, 8, 21, 23, 0)),
])
def test_get_midnight_for_day_before_returns_expected_date(date, expected_date):
assert get_midnight_for_day_before(date) == expected_date