Adding a filter to exclude test keys for the template monthly usage query.

Added a test.
This commit is contained in:
Rebecca Law
2019-01-15 16:13:38 +00:00
parent 3fdf0c7822
commit a4d89359c5
2 changed files with 20 additions and 1 deletions

View File

@@ -312,7 +312,8 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
FactNotificationStatus.service_id == service_id,
FactNotificationStatus.bst_date >= start_date,
FactNotificationStatus.bst_date <= end_date,
FactNotificationStatus.notification_status != NOTIFICATION_CANCELLED
FactNotificationStatus.key_type != KEY_TYPE_TEST,
FactNotificationStatus.notification_status != NOTIFICATION_CANCELLED,
).group_by(
FactNotificationStatus.template_id,
Template.name,

View File

@@ -461,3 +461,21 @@ def test_fetch_monthly_template_usage_for_service_does_not_include_cancelled_sta
)
assert len(results) == 0
@freeze_time('2018-03-30 14:00')
def test_fetch_monthly_template_usage_for_service_does_not_include_test_notifications(
sample_template
):
create_ft_notification_status(bst_date=date(2018, 3, 1),
service=sample_template.service,
template=sample_template,
notification_status='delivered',
key_type='test',
count=15)
create_notification(template=sample_template, created_at=datetime.utcnow(), status='cancelled')
results = fetch_monthly_template_usage_for_service(
datetime(2018, 1, 1), datetime(2018, 3, 31), sample_template.service_id
)
assert len(results) == 0