diff --git a/app/celery/reporting_tasks.py b/app/celery/reporting_tasks.py index 07e0a66c6..b803fbe11 100644 --- a/app/celery/reporting_tasks.py +++ b/app/celery/reporting_tasks.py @@ -18,13 +18,13 @@ from app.dao.fact_notification_status_dao import fetch_notification_status_for_d @statsd(namespace="tasks") def create_nightly_billing(day_start=None): # day_start is a datetime.date() object. e.g. - # up to 10 days of data counting back from day_start is consolidated + # up to 4 days of data counting back from day_start is consolidated if day_start is None: day_start = convert_utc_to_bst(datetime.utcnow()).date() - timedelta(days=1) else: # When calling the task its a string in the format of "YYYY-MM-DD" day_start = datetime.strptime(day_start, "%Y-%m-%d").date() - for i in range(0, 10): + for i in range(0, 4): process_day = day_start - timedelta(days=i) transit_data = fetch_billing_data_for_day(process_day=process_day) @@ -47,7 +47,7 @@ def create_nightly_notification_status(day_start=None): else: # When calling the task its a string in the format of "YYYY-MM-DD" day_start = datetime.strptime(day_start, "%Y-%m-%d").date() - for i in range(0, 10): + for i in range(0, 4): process_day = day_start - timedelta(days=i) transit_data = fetch_notification_status_for_day(process_day=process_day) diff --git a/tests/app/celery/test_reporting_tasks.py b/tests/app/celery/test_reporting_tasks.py index d4d11773c..3dcb15925 100644 --- a/tests/app/celery/test_reporting_tasks.py +++ b/tests/app/celery/test_reporting_tasks.py @@ -444,14 +444,10 @@ def test_create_nightly_notification_status(notify_db_session): create_notification(template=first_template, status='delivered', created_at=datetime.utcnow() - timedelta(days=10)) create_notification(template=second_template, status='temporary-failure') - create_notification(template=second_template, status='temporary-failure', - created_at=datetime.utcnow() - timedelta(days=1)) - create_notification(template=second_template, status='temporary-failure', - created_at=datetime.utcnow() - timedelta(days=2)) - create_notification(template=second_template, status='temporary-failure', - created_at=datetime.utcnow() - timedelta(days=10)) - create_notification(template=second_template, status='temporary-failure', - created_at=datetime.utcnow() - timedelta(days=10)) + create_notification(template=second_template, status='temporary-failure', created_at=datetime.utcnow() - timedelta(days=1)) # noqa + create_notification(template=second_template, status='temporary-failure', created_at=datetime.utcnow() - timedelta(days=2)) # noqa + create_notification(template=second_template, status='temporary-failure', created_at=datetime.utcnow() - timedelta(days=10)) # noqa + create_notification(template=second_template, status='temporary-failure', created_at=datetime.utcnow() - timedelta(days=10)) # noqa create_notification(template=third_template, status='created') create_notification(template=third_template, status='created', created_at=datetime.utcnow() - timedelta(days=1)) @@ -464,12 +460,14 @@ def test_create_nightly_notification_status(notify_db_session): create_nightly_notification_status() new_data = FactNotificationStatus.query.order_by( FactNotificationStatus.bst_date, - FactNotificationStatus.notification_type ).all() - assert len(new_data) == 9 - assert str(new_data[0].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=10), "%Y-%m-%d") - assert str(new_data[3].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=2), "%Y-%m-%d") - assert str(new_data[6].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=1), "%Y-%m-%d") + assert len(new_data) == 6 # + assert str(new_data[0].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=2), "%Y-%m-%d") + assert str(new_data[1].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=2), "%Y-%m-%d") + assert str(new_data[2].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=2), "%Y-%m-%d") + assert str(new_data[3].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=1), "%Y-%m-%d") + assert str(new_data[4].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=1), "%Y-%m-%d") + assert str(new_data[5].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=1), "%Y-%m-%d") # the job runs at 12:30am London time. 04/01 is in BST.