update time handling for more tests

This commit is contained in:
stvnrlly
2022-11-10 16:54:48 -05:00
parent b50cb4712f
commit 3528bd37e1
10 changed files with 43 additions and 43 deletions

View File

@@ -233,7 +233,7 @@ def test_check_billable_units_when_billable_units_does_not_match_page_count(
@pytest.mark.parametrize('filename_date, billing_date', [
('20170820230000', date(2017, 8, 21)),
('20170820000000', date(2017, 8, 19)),
('20170120230000', date(2017, 1, 20))
])
def test_get_billing_date_in_est_from_filename(filename_date, billing_date):

View File

@@ -471,7 +471,7 @@ def test_get_rate_for_sms_and_email(notify_db_session):
assert rate == Decimal(0)
@freeze_time('2018-03-30T01:00:00')
@freeze_time('2018-03-26T04:30:00')
# summer time starts on 2018-03-25
def test_create_nightly_billing_for_day_use_BST(
sample_service,
@@ -482,7 +482,7 @@ def test_create_nightly_billing_for_day_use_BST(
# too late
create_notification(
created_at=datetime(2018, 3, 25, 23, 1),
created_at=datetime(2018, 3, 26, 4, 1),
template=sample_template,
status='delivered',
rate_multiplier=1.0,
@@ -490,7 +490,7 @@ def test_create_nightly_billing_for_day_use_BST(
)
create_notification(
created_at=datetime(2018, 3, 25, 22, 59),
created_at=datetime(2018, 3, 26, 3, 59),
template=sample_template,
status='delivered',
rate_multiplier=1.0,
@@ -499,7 +499,7 @@ def test_create_nightly_billing_for_day_use_BST(
# too early
create_notification(
created_at=datetime(2018, 3, 24, 23, 59),
created_at=datetime(2018, 3, 25, 4, 59),
template=sample_template,
status='delivered',
rate_multiplier=1.0,
@@ -517,7 +517,7 @@ def test_create_nightly_billing_for_day_use_BST(
assert records[0].billable_units == 2
@freeze_time('2018-01-15T03:30:00')
@freeze_time('2018-01-15T08:30:00')
def test_create_nightly_billing_for_day_update_when_record_exists(
sample_service,
sample_template,
@@ -571,7 +571,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
third_template = create_template(service=second_service, template_type='letter')
process_day = date.today() - timedelta(days=5)
with freeze_time(datetime.combine(process_day, time.min)):
with freeze_time(datetime.combine(process_day, time.max)):
create_notification(template=first_template, status='delivered')
create_notification(template=second_template, status='temporary-failure')
@@ -585,7 +585,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
create_notification_history(template=third_template, status='delivered')
# these created notifications from a different day get ignored
with freeze_time(datetime.combine(date.today() - timedelta(days=4), time.min)):
with freeze_time(datetime.combine(date.today() - timedelta(days=4), time.max)):
create_notification(template=first_template)
create_notification_history(template=second_template)
create_notification(template=third_template)
@@ -671,14 +671,14 @@ def test_create_nightly_notification_status_for_service_and_day_overwrites_old_d
# the job runs at 12:30am London time. 04/01 is in BST.
@freeze_time('2019-04-01T23:30')
@freeze_time('2019-04-02T04:30')
def test_create_nightly_notification_status_for_service_and_day_respects_bst(sample_template):
create_notification(sample_template, status='delivered', created_at=datetime(2019, 4, 1, 23, 0)) # too new
create_notification(sample_template, status='delivered', created_at=datetime(2019, 4, 2, 5, 0)) # too new
create_notification(sample_template, status='created', created_at=datetime(2019, 4, 1, 22, 59))
create_notification(sample_template, status='created', created_at=datetime(2019, 3, 31, 23, 0))
create_notification(sample_template, status='created', created_at=datetime(2019, 4, 2, 5, 59))
create_notification(sample_template, status='created', created_at=datetime(2019, 4, 1, 4, 0))
create_notification(sample_template, status='delivered', created_at=datetime(2019, 3, 31, 22, 59)) # too old
create_notification(sample_template, status='delivered', created_at=datetime(2019, 3, 21, 17, 59)) # too old
create_nightly_notification_status_for_service_and_day('2019-04-01', sample_template.service_id, 'sms')

View File

@@ -97,8 +97,8 @@ def test_post_to_get_inbound_sms_allows_badly_formatted_number(admin_request, sa
@freeze_time('Monday 10th April 2017 12:00')
def test_post_to_get_most_recent_inbound_sms_for_service_limits_to_a_week(admin_request, sample_service):
create_inbound_sms(sample_service, created_at=datetime(2017, 4, 2, 22, 59))
returned_inbound = create_inbound_sms(sample_service, created_at=datetime(2017, 4, 2, 23, 30))
create_inbound_sms(sample_service, created_at=datetime(2017, 4, 3, 3, 59))
returned_inbound = create_inbound_sms(sample_service, created_at=datetime(2017, 4, 3, 4, 30))
sms = admin_request.post('inbound_sms.post_inbound_sms_for_service', service_id=sample_service.id, _data={})

View File

@@ -878,10 +878,10 @@ def test_get_all_notifications_for_job_returns_csv_format(admin_request, sample_
}
@freeze_time('2017-06-10 12:00')
@freeze_time('2017-06-10 04:00')
def test_get_jobs_should_retrieve_from_ft_notification_status_for_old_jobs(admin_request, sample_template):
# it's the 10th today, so 3 days should include all of 7th, 8th, 9th, and some of 10th.
just_three_days_ago = datetime(2017, 6, 6, 22, 59, 59)
just_three_days_ago = datetime(2017, 6, 7, 3, 59, 59)
not_quite_three_days_ago = just_three_days_ago + timedelta(seconds=1)
job_1 = create_job(sample_template, created_at=just_three_days_ago, processing_started=just_three_days_ago)

View File

@@ -2162,10 +2162,10 @@ def test_get_detailed_services_includes_services_with_no_notifications(notify_db
def test_get_detailed_services_only_includes_todays_notifications(sample_template):
from app.service.rest import get_detailed_services
create_notification(sample_template, created_at=datetime(2015, 10, 9, 23, 59))
create_notification(sample_template, created_at=datetime(2015, 10, 10, 0, 0))
create_notification(sample_template, created_at=datetime(2015, 10, 10, 3, 59))
create_notification(sample_template, created_at=datetime(2015, 10, 10, 4, 0))
create_notification(sample_template, created_at=datetime(2015, 10, 10, 12, 0))
create_notification(sample_template, created_at=datetime(2015, 10, 10, 23, 0))
create_notification(sample_template, created_at=datetime(2015, 10, 11, 3, 0))
with freeze_time('2015-10-10T12:00:00'):
data = get_detailed_services(start_date=datetime.utcnow().date(), end_date=datetime.utcnow().date())

View File

@@ -175,7 +175,7 @@ def _stats(requested, delivered, failed):
]
)
])
@freeze_time('2018-05-31 23:59:59')
@freeze_time('2018-06-01 04:59:59')
def test_create_empty_monthly_notification_status_stats_dict(year, expected_years):
output = create_empty_monthly_notification_status_stats_dict(year)
assert sorted(output.keys()) == expected_years
@@ -183,7 +183,7 @@ def test_create_empty_monthly_notification_status_stats_dict(year, expected_year
assert v == {'sms': {}, 'email': {}, 'letter': {}}
@freeze_time('2018-05-31 23:59:59')
@freeze_time('2018-06-01 04:59:59')
def test_add_monthly_notification_status_stats():
row_data = [
{'month': datetime(2018, 4, 1), 'notification_type': 'sms', 'notification_status': 'sending', 'count': 1},

View File

@@ -1,5 +1,5 @@
import uuid
from datetime import date, datetime
from datetime import date, datetime, timedelta
import pytest
from freezegun import freeze_time
@@ -21,7 +21,7 @@ from tests.app.db import (
)
@freeze_time('2017-11-11 02:00')
@freeze_time('2017-11-11 06:00')
def test_get_template_usage_by_month_returns_correct_data(
admin_request,
sample_template
@@ -53,7 +53,7 @@ def test_get_template_usage_by_month_returns_correct_data(
assert resp_json[1]["count"] == 1
@freeze_time('2017-11-11 02:00')
@freeze_time('2017-11-11 06:00')
def test_get_template_usage_by_month_returns_two_templates(admin_request, sample_template, sample_service):
template_one = create_template(
sample_service,
@@ -213,14 +213,14 @@ def test_get_monthly_notification_stats_returns_stats(admin_request, sample_serv
@freeze_time('2016-06-05 12:00:00')
def test_get_monthly_notification_stats_combines_todays_data_and_historic_stats(admin_request, sample_template):
create_ft_notification_status(datetime(2016, 5, 1), template=sample_template, count=1)
create_ft_notification_status(datetime(2016, 6, 1), template=sample_template, notification_status='created', count=2) # noqa
create_ft_notification_status(datetime(2016, 5, 1, 12), template=sample_template, count=1)
create_ft_notification_status(datetime(2016, 6, 1, 12), template=sample_template, notification_status='created', count=2) # noqa
create_notification(sample_template, created_at=datetime(2016, 6, 5), status='created')
create_notification(sample_template, created_at=datetime(2016, 6, 5), status='delivered')
create_notification(sample_template, created_at=datetime(2016, 6, 5, 12), status='created')
create_notification(sample_template, created_at=datetime(2016, 6, 5, 12), status='delivered')
# this doesn't get returned in the stats because it is old - it should be in ft_notification_status by now
create_notification(sample_template, created_at=datetime(2016, 6, 4), status='sending')
create_notification(sample_template, created_at=datetime(2016, 6, 4, 12), status='sending')
response = admin_request.get(
'service.get_monthly_notification_stats',
@@ -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), template=t, notification_status='created')
create_ft_notification_status(datetime(2016, 4, 1), 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')
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')
response = admin_request.get('service.get_monthly_notification_stats', service_id=sample_service.id, year=2016)

View File

@@ -4,13 +4,13 @@ from app.dao.date_util import get_current_financial_year_start_year
# see get_financial_year for conversion of financial years.
@freeze_time("2017-03-31 22:59:59.999999")
@freeze_time("2017-04-01 03:59:59.999999")
def test_get_current_financial_year_start_year_before_march():
current_fy = get_current_financial_year_start_year()
assert current_fy == 2016
@freeze_time("2017-03-31 23:00:00.000000")
@freeze_time("2017-04-01 04:00:00.000000")
def test_get_current_financial_year_start_year_after_april():
current_fy = get_current_financial_year_start_year()
assert current_fy == 2017

View File

@@ -145,7 +145,7 @@ def test_notification_for_csv_returns_bst_correctly(sample_template):
notification = create_notification(sample_template)
serialized = notification.serialize_for_csv()
assert serialized['created_at'] == '2017-03-27 00:01:53'
assert serialized['created_at'] == '2017-03-26 19:01:53'
def test_notification_personalisation_getter_returns_empty_dict_from_None():

View File

@@ -72,7 +72,7 @@ def test_get_uploads(admin_request, sample_template):
'recipient': None,
'notification_count': 2,
'template_type': 'letter',
'created_at': upload_4.created_at.replace(hour=17, minute=30).strftime(
'created_at': upload_4.created_at.replace(hour=22, minute=30).strftime(
"%Y-%m-%d %H:%M:%S"),
'statistics': [],
'upload_type': 'letter_day'}
@@ -146,7 +146,7 @@ def test_get_uploads_accepts_page_parameter(admin_request, sample_template):
@freeze_time('2017-06-10 12:00')
def test_get_uploads_should_retrieve_from_ft_notification_status_for_old_jobs(admin_request, sample_template):
# it's the 10th today, so 3 days should include all of 7th, 8th, 9th, and some of 10th.
just_three_days_ago = datetime(2017, 6, 6, 22, 59, 59)
just_three_days_ago = datetime(2017, 6, 7, 3, 59, 59)
not_quite_three_days_ago = just_three_days_ago + timedelta(seconds=1)
job_1 = create_job(sample_template, created_at=just_three_days_ago, processing_started=just_three_days_ago)
@@ -155,15 +155,15 @@ def test_get_uploads_should_retrieve_from_ft_notification_status_for_old_jobs(ad
job_3 = create_job(sample_template, created_at=just_three_days_ago, processing_started=None)
# some notifications created more than three days ago, some created after the midnight cutoff
create_ft_notification_status(date(2017, 6, 6), job=job_1, notification_status='delivered', count=2)
create_ft_notification_status(date(2017, 6, 7), job=job_1, notification_status='delivered', count=4)
create_ft_notification_status(datetime(2017, 6, 6, 12), job=job_1, notification_status='delivered', count=2)
create_ft_notification_status(datetime(2017, 6, 7, 12), job=job_1, notification_status='delivered', count=4)
# job2's new enough
create_notification(job=job_2, status='created', created_at=not_quite_three_days_ago)
# this isn't picked up because the job is too new
create_ft_notification_status(date(2017, 6, 7), job=job_2, notification_status='delivered', count=8)
create_ft_notification_status(datetime(2017, 6, 7, 12), job=job_2, notification_status='delivered', count=8)
# this isn't picked up - while the job is old, it started in last 3 days so we look at notification table instead
create_ft_notification_status(date(2017, 6, 7), job=job_3, notification_status='delivered', count=16)
create_ft_notification_status(datetime(2017, 6, 7, 12), job=job_3, notification_status='delivered', count=16)
# this isn't picked up because we're using the ft status table for job_1 as it's old
create_notification(job=job_1, status='created', created_at=not_quite_three_days_ago)