diff --git a/app/dao/annual_billing_dao.py b/app/dao/annual_billing_dao.py index 0366e3826..b91604d20 100644 --- a/app/dao/annual_billing_dao.py +++ b/app/dao/annual_billing_dao.py @@ -1,7 +1,5 @@ from app import db -from app.dao.dao_utils import ( - transactional, -) +from app.dao.dao_utils import transactional from app.models import AnnualBilling from app.dao.date_util import get_current_financial_year_start_year diff --git a/app/dao/fact_notification_status_dao.py b/app/dao/fact_notification_status_dao.py index 61dfdc01d..114db7ae4 100644 --- a/app/dao/fact_notification_status_dao.py +++ b/app/dao/fact_notification_status_dao.py @@ -27,6 +27,7 @@ from app.models import ( SMS_TYPE, Template, ) +from app.dao.dao_utils import transactional from app.utils import ( get_london_midnight_in_utc, midnight_n_days_ago, @@ -90,6 +91,7 @@ def query_for_fact_status_data(table, start_date, end_date, notification_type, s return query.all() +@transactional def update_fact_notification_status(data, process_day): table = FactNotificationStatus.__table__ FactNotificationStatus.query.filter( @@ -108,7 +110,6 @@ def update_fact_notification_status(data, process_day): notification_count=row.notification_count, ) db.session.connection().execute(stmt) - db.session.commit() def fetch_notification_status_for_service_by_month(start_date, end_date, service_id): diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index 4cdd8b3e8..70c16e08d 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -85,6 +85,7 @@ def test_get_notification_table_to_use_respects_daylight_savings_time(sample_ser @freeze_time('2019-01-10 00:30') 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 @@ -92,6 +93,9 @@ def test_get_notification_table_to_use_checks_service_data_retention(sample_serv 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