mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 08:21:13 -05:00
add transactional wrapper
and add case to get_notification_table_to_use test
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
from app import db
|
from app import db
|
||||||
from app.dao.dao_utils import (
|
from app.dao.dao_utils import transactional
|
||||||
transactional,
|
|
||||||
)
|
|
||||||
from app.models import AnnualBilling
|
from app.models import AnnualBilling
|
||||||
from app.dao.date_util import get_current_financial_year_start_year
|
from app.dao.date_util import get_current_financial_year_start_year
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ from app.models import (
|
|||||||
SMS_TYPE,
|
SMS_TYPE,
|
||||||
Template,
|
Template,
|
||||||
)
|
)
|
||||||
|
from app.dao.dao_utils import transactional
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
get_london_midnight_in_utc,
|
get_london_midnight_in_utc,
|
||||||
midnight_n_days_ago,
|
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()
|
return query.all()
|
||||||
|
|
||||||
|
|
||||||
|
@transactional
|
||||||
def update_fact_notification_status(data, process_day):
|
def update_fact_notification_status(data, process_day):
|
||||||
table = FactNotificationStatus.__table__
|
table = FactNotificationStatus.__table__
|
||||||
FactNotificationStatus.query.filter(
|
FactNotificationStatus.query.filter(
|
||||||
@@ -108,7 +110,6 @@ def update_fact_notification_status(data, process_day):
|
|||||||
notification_count=row.notification_count,
|
notification_count=row.notification_count,
|
||||||
)
|
)
|
||||||
db.session.connection().execute(stmt)
|
db.session.connection().execute(stmt)
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_notification_status_for_service_by_month(start_date, end_date, service_id):
|
def fetch_notification_status_for_service_by_month(start_date, end_date, service_id):
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ def test_get_notification_table_to_use_respects_daylight_savings_time(sample_ser
|
|||||||
@freeze_time('2019-01-10 00:30')
|
@freeze_time('2019-01-10 00:30')
|
||||||
def test_get_notification_table_to_use_checks_service_data_retention(sample_service):
|
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, '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.
|
# 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
|
# 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, 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, '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
|
# 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, 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, 2), False) == Notification
|
||||||
|
|||||||
Reference in New Issue
Block a user