add transactional wrapper

and add case to get_notification_table_to_use test
This commit is contained in:
Leo Hemsted
2019-12-04 15:26:26 +00:00
parent dd57468147
commit 8d160303a1
3 changed files with 7 additions and 4 deletions

View File

@@ -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

View File

@@ -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):

View File

@@ -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