In order to re-run the create_nightly_billing for dates in the past, we added a condition on which table is used.

This will allow us to re-run nightly billing for those 2 days where it failed.
For the majority of time the query will run on Notiifcations.
This commit is contained in:
Rebecca Law
2018-05-14 16:21:16 +01:00
parent a640605a7c
commit 3615f3d00f
2 changed files with 42 additions and 23 deletions

View File

@@ -10,7 +10,7 @@ from app.dao.fact_billing_dao import (
get_rate,
fetch_billing_totals_for_year,
)
from app.models import FactBilling
from app.models import FactBilling, Notification
from app.utils import convert_utc_to_bst
from tests.app.db import (
create_ft_billing,
@@ -187,6 +187,19 @@ def test_fetch_billing_data_for_day_returns_empty_list(notify_db_session):
assert results == []
def test_fetch_billing_data_for_day_uses_notification_history(notify_db_session):
service = create_service()
sms_template = create_template(service=service, template_type='sms')
create_notification(template=sms_template, status='delivered', created_at=datetime.utcnow() - timedelta(days=8))
create_notification(template=sms_template, status='delivered', created_at=datetime.utcnow() - timedelta(days=8))
Notification.query.delete()
db.session.commit()
results = fetch_billing_data_for_day(process_day=datetime.utcnow() - timedelta(days=8), service_id=service.id)
assert len(results) == 1
assert results[0].notifications_sent == 2
def test_fetch_billing_data_for_day_returns_list_for_given_service(notify_db_session):
service = create_service()
service_2 = create_service(service_name='Service 2')