diff --git a/app/dao/statistics_dao.py b/app/dao/statistics_dao.py index 20c75112e..baff82ba4 100644 --- a/app/dao/statistics_dao.py +++ b/app/dao/statistics_dao.py @@ -14,6 +14,7 @@ from app.models import ( SMS_TYPE, LETTER_TYPE, NOTIFICATION_STATUS_TYPES_FAILED, + NOTIFICATION_STATUS_SUCCESS, NOTIFICATION_DELIVERED, NOTIFICATION_SENT) from app.statsd_decorators import statsd @@ -32,6 +33,7 @@ def timeout_job_counts(notifications_type, timeout_start): func.count(Notification.status).label('count'), Notification.status.label('status') ).filter( + Notification.notification_type == notifications_type, JobStatistics.job_id == Notification.job_id, JobStatistics.created_at < timeout_start, sent != failed + delivered @@ -47,7 +49,7 @@ def timeout_job_counts(notifications_type, timeout_start): delivered_count = 0 failed_count = 0 for notification_status in job: - if notification_status.status in [NOTIFICATION_DELIVERED, NOTIFICATION_SENT]: + if notification_status.status in NOTIFICATION_STATUS_SUCCESS: delivered_count += notification_status.count else: failed_count += notification_status.count diff --git a/tests/app/dao/test_statistics_dao.py b/tests/app/dao/test_statistics_dao.py index 23e15f65f..4425a3409 100644 --- a/tests/app/dao/test_statistics_dao.py +++ b/tests/app/dao/test_statistics_dao.py @@ -780,7 +780,7 @@ def test_timeout_job_sets_all_non_delivered_emails_to_error_and_doesnt_affect_sm assert sms_stats[0].emails_delivered == 0 assert sms_stats[0].sms_delivered == 0 assert sms_stats[0].sms_failed == 1 - assert sms_stats[0].emails_failed == 100 + assert sms_stats[0].emails_failed == 0 # this test is as above, but for SMS not email