mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
time adjustments in tests
This commit is contained in:
@@ -2,7 +2,10 @@ from datetime import date, datetime, time, timedelta
|
||||
from os import getenv
|
||||
|
||||
import pytz
|
||||
from notifications_utils.timezones import convert_local_timezone_to_utc, convert_utc_to_local_timezone
|
||||
from notifications_utils.timezones import (
|
||||
convert_local_timezone_to_utc,
|
||||
convert_utc_to_local_timezone,
|
||||
)
|
||||
|
||||
|
||||
def get_months_for_financial_year(year):
|
||||
@@ -47,8 +50,8 @@ def get_april_fools(year):
|
||||
:param year: the year to calculate the April 1, 00:00 BST for
|
||||
:return: the datetime of April 1 for the given year, for example 2016 = 2016-03-31 23:00:00
|
||||
"""
|
||||
return pytz.timezone(getenv("TIMEZONE", "America/New_York")).localize(datetime(year, 4, 1, 0, 0, 0)).astimezone(pytz.UTC).replace(
|
||||
tzinfo=None)
|
||||
return pytz.timezone(getenv("TIMEZONE", "America/New_York")).localize(
|
||||
datetime(year, 4, 1, 0, 0, 0)).astimezone(pytz.UTC).replace(tzinfo=None)
|
||||
|
||||
|
||||
def get_month_start_and_end_date_in_utc(month_year):
|
||||
|
||||
@@ -12,7 +12,10 @@ from notifications_utils.recipients import (
|
||||
try_validate_and_format_phone_number,
|
||||
validate_and_format_email_address,
|
||||
)
|
||||
from notifications_utils.timezones import convert_local_timezone_to_utc, convert_utc_to_local_timezone
|
||||
from notifications_utils.timezones import (
|
||||
convert_local_timezone_to_utc,
|
||||
convert_utc_to_local_timezone,
|
||||
)
|
||||
from sqlalchemy import and_, asc, desc, func, or_, union
|
||||
from sqlalchemy.orm import joinedload
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
@@ -583,7 +583,9 @@ def get_monthly_notification_stats(service_id):
|
||||
|
||||
now = datetime.utcnow()
|
||||
if end_date > now:
|
||||
todays_deltas = fetch_notification_status_for_service_for_day(convert_utc_to_local_timezone(now), service_id=service_id)
|
||||
todays_deltas = fetch_notification_status_for_service_for_day(
|
||||
convert_utc_to_local_timezone(now), service_id=service_id
|
||||
)
|
||||
statistics.add_monthly_notification_status_stats(data, todays_deltas)
|
||||
|
||||
return jsonify(data=data)
|
||||
|
||||
@@ -46,7 +46,7 @@ def mocker_get_rate(
|
||||
return Decimal(0)
|
||||
|
||||
|
||||
@freeze_time('2019-08-01')
|
||||
@freeze_time('2019-08-01T05:30')
|
||||
@pytest.mark.parametrize('day_start, expected_kwargs', [
|
||||
(None, [f'2019-07-{31-i}' for i in range(10)]),
|
||||
('2019-07-21', [f'2019-07-{21-i}' for i in range(10)]),
|
||||
@@ -77,7 +77,7 @@ def test_create_nightly_notification_status_triggers_tasks(
|
||||
mock_celery.assert_called_with(
|
||||
kwargs={
|
||||
'service_id': sample_service.id,
|
||||
'process_day': '2019-07-31',
|
||||
'process_day': '2019-07-30',
|
||||
'notification_type': SMS_TYPE
|
||||
},
|
||||
queue=QueueNames.REPORTING
|
||||
@@ -499,7 +499,7 @@ def test_create_nightly_billing_for_day_use_BST(
|
||||
|
||||
# too early
|
||||
create_notification(
|
||||
created_at=datetime(2018, 3, 25, 4, 59),
|
||||
created_at=datetime(2018, 3, 25, 3, 59),
|
||||
template=sample_template,
|
||||
status='delivered',
|
||||
rate_multiplier=1.0,
|
||||
|
||||
@@ -41,7 +41,7 @@ def test_get_month_start_and_end_date_in_utc(month, year, expected_start, expect
|
||||
(datetime(2019, 4, 1, 3, 59, 59), 2018),
|
||||
(datetime(2019, 4, 1, 4, 0, 0), 2019),
|
||||
(date(2019, 3, 31), 2018),
|
||||
(date(2019, 4, 2), 2019), # date() gives midnight UTC, which is the day before in ET
|
||||
(date(2019, 4, 2), 2019), # date() gives midnight UTC, which is the day before in ET
|
||||
])
|
||||
def test_get_financial_year_for_datetime(dt, fy):
|
||||
assert get_financial_year_for_datetime(dt) == fy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import uuid
|
||||
from datetime import date, datetime, timedelta
|
||||
from datetime import date, datetime
|
||||
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
@@ -61,8 +61,8 @@ def test_get_template_usage_by_month_returns_two_templates(admin_request, sample
|
||||
template_name=PRECOMPILED_TEMPLATE_NAME,
|
||||
hidden=True
|
||||
)
|
||||
create_ft_notification_status(bst_date=datetime(2017, 4, 1), template=template_one, count=1)
|
||||
create_ft_notification_status(bst_date=datetime(2017, 4, 1), template=sample_template, count=3)
|
||||
create_ft_notification_status(bst_date=datetime(2017, 4, 2), template=template_one, count=1)
|
||||
create_ft_notification_status(bst_date=datetime(2017, 4, 2), template=sample_template, count=3)
|
||||
create_notification(sample_template, created_at=datetime.utcnow())
|
||||
|
||||
resp_json = admin_request.get(
|
||||
@@ -259,10 +259,10 @@ def test_get_monthly_notification_stats_ignores_test_keys(admin_request, sample_
|
||||
|
||||
def test_get_monthly_notification_stats_checks_dates(admin_request, sample_service):
|
||||
t = create_template(sample_service)
|
||||
create_ft_notification_status(datetime(2016, 3, 31, 12), template=t, notification_status='created')
|
||||
create_ft_notification_status(datetime(2016, 4, 1, 12), template=t, notification_status='sending')
|
||||
create_ft_notification_status(datetime(2017, 3, 31, 12), template=t, notification_status='delivered')
|
||||
create_ft_notification_status(datetime(2017, 4, 11, 12), template=t, notification_status='permanent-failure')
|
||||
create_ft_notification_status(datetime(2016, 3, 31), template=t, notification_status='created')
|
||||
create_ft_notification_status(datetime(2016, 4, 2), template=t, notification_status='sending')
|
||||
create_ft_notification_status(datetime(2017, 3, 31), template=t, notification_status='delivered')
|
||||
create_ft_notification_status(datetime(2017, 4, 11), template=t, notification_status='permanent-failure')
|
||||
|
||||
response = admin_request.get('service.get_monthly_notification_stats', service_id=sample_service.id, year=2016)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import date, datetime, timedelta
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from freezegun import freeze_time
|
||||
|
||||
|
||||
Reference in New Issue
Block a user