def test_get_notification_table_to_use(sample_service): # it's currently early morning of Thurs 10th Jan. # When the delete task runs a bit later, it'll delete data from last wednesday 2nd. assert get_notification_table_to_use(sample_service, 'sms', date(2018, 12, 31), False) == NotificationHistory assert get_notification_table_to_use(sample_service, 'sms', date(2019, 1, 1), False) == NotificationHistory assert get_notification_table_to_use(sample_service, 'sms', date(2019, 1, 2), False) == Notification assert get_notification_table_to_use(sample_service, 'sms', date(2019, 1, 3), False) == Notification
def test_get_notification_table_to_use_respects_daylight_savings_time( sample_service): # current time is 12:30am on 10th july in BST assert get_notification_table_to_use(sample_service, 'sms', date(2019, 6, 1), False) == NotificationHistory assert get_notification_table_to_use(sample_service, 'sms', date(2019, 6, 2), False) == Notification
def test_get_notification_table_to_use_knows_if_delete_task_has_run( sample_service): # it's currently early morning of Thurs 10th Jan. # The delete task deletes/moves data from last wednesday 2nd. assert get_notification_table_to_use(sample_service, 'sms', date(2019, 1, 2), False) == Notification assert get_notification_table_to_use(sample_service, 'sms', date(2019, 1, 2), True) == NotificationHistory
def fetch_notification_status_for_day(process_day, notification_type): start_date = convert_bst_to_utc(datetime.combine(process_day, time.min)) end_date = convert_bst_to_utc( datetime.combine(process_day + timedelta(days=1), time.min)) current_app.logger.info("Fetch ft_notification_status for {} to {}".format( start_date, end_date)) all_data_for_process_day = [] services = Service.query.all() # for each service query notifications or notification_history for the day, depending on their data retention for service in services: table = get_notification_table_to_use(service, notification_type, process_day, has_delete_task_run=False) data_for_service_and_type = query_for_fact_status_data( table=table, start_date=start_date, end_date=end_date, notification_type=notification_type, service_id=service.id) all_data_for_process_day += data_for_service_and_type return all_data_for_process_day
def fetch_billing_data_for_day(process_day, service_id=None, check_permissions=False): start_date = convert_bst_to_utc(datetime.combine(process_day, time.min)) end_date = convert_bst_to_utc( datetime.combine(process_day + timedelta(days=1), time.min)) current_app.logger.info("Populate ft_billing for {} to {}".format( start_date, end_date)) transit_data = [] if not service_id: services = Service.query.all() else: services = [Service.query.get(service_id)] for service in services: for notification_type in (SMS_TYPE, EMAIL_TYPE, LETTER_TYPE): if (not check_permissions ) or service.has_permission(notification_type): table = get_notification_table_to_use( service, notification_type, process_day, has_delete_task_run=False) results = _query_for_billing_data( table=table, notification_type=notification_type, start_date=start_date, end_date=end_date, service=service) transit_data += results return transit_data
def test_get_notification_table_to_use_checks_service_data_retention( sample_service): create_service_data_retention(sample_service, 'email', days_of_retention=3) create_service_data_retention(sample_service, 'letter', days_of_retention=9) # it's currently early morning of Thurs 10th Jan. # three days retention means we'll delete sunday 6th's data when the delete task runs (so there's still three full # days of monday, tuesday and wednesday left over) assert get_notification_table_to_use(sample_service, 'email', date(2019, 1, 5), False) == NotificationHistory assert get_notification_table_to_use(sample_service, 'email', date(2019, 1, 6), False) == Notification assert get_notification_table_to_use(sample_service, 'letter', date(2018, 12, 30), False) == NotificationHistory assert get_notification_table_to_use(sample_service, 'letter', date(2018, 12, 31), False) == Notification # falls back to 7 days if not specified assert get_notification_table_to_use(sample_service, 'sms', date(2019, 1, 1), False) == NotificationHistory assert get_notification_table_to_use(sample_service, 'sms', date(2019, 1, 2), False) == Notification