mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
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:
@@ -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')
|
||||
])
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user