def test_get_total_sent_notifications_yesterday_returns_expected_totals_dict( notify_db, notify_db_session, sample_template): notification_history = partial(create_notification_history, notify_db, notify_db_session, sample_template, status='delivered') notification_history(notification_type='email') notification_history(notification_type='sms') # Create some notifications for the day before yesterday = datetime(2016, 1, 10, 12, 30, 0, 0) # 2016-01-10 11:30pm AEDT ereyesterday = datetime(2016, 1, 9, 12, 30, 0, 0) # 2016-01-09 11:30pm AEDT with freeze_time(yesterday): notification_history(notification_type='letter') notification_history(notification_type='sms') notification_history(notification_type='sms') notification_history(notification_type='email') notification_history(notification_type='email') notification_history(notification_type='email') total_count_dict = get_total_sent_notifications_for_day(yesterday) assert total_count_dict == { "start_date": get_midnight_for_day_before(datetime.utcnow()), "email": { "count": 3 }, "sms": { "count": 2 }, "letter": { "count": 1 } } another_day = get_total_sent_notifications_for_day(ereyesterday) assert another_day == { 'email': { 'count': 0 }, 'letter': { 'count': 0 }, 'sms': { 'count': 0 }, 'start_date': datetime(2016, 1, 8, 13, 00), }
def backfill_processing_time(start_date, end_date): """ Send historical processing time to Performance Platform. """ delta = end_date - start_date print('Sending notification processing-time data for all days between {} and {}'.format(start_date, end_date)) for i in range(delta.days + 1): # because the tz conversion funcs talk about midnight, and the midnight before last, # we want to pretend we're running this from the next morning, so add one. process_date = start_date + timedelta(days=i + 1) process_start_date = get_midnight_for_day_before(process_date) process_end_date = get_local_timezone_midnight_in_utc(process_date) print('Sending notification processing-time for {} - {}'.format( process_start_date.isoformat(), process_end_date.isoformat() )) send_processing_time_for_start_and_end(process_start_date, process_end_date)
def test_get_midnight_for_day_before_returns_expected_date( date, expected_date): assert get_midnight_for_day_before(date) == expected_date
def send_processing_time_to_performance_platform(): today = datetime.utcnow() start_date = get_midnight_for_day_before(today) end_date = get_london_midnight_in_utc(today) send_processing_time_for_start_and_end(start_date, end_date)