diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 045daec0d..d21e8bd49 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -246,6 +246,7 @@ def dao_fetch_monthly_historical_stats_by_template_for_service(service_id, year) rows = db.session.query( Template.id.label('template_id'), Template.name, + Template.template_type, sq.c.status, sq.c.count.label('count'), sq.c.month diff --git a/app/service/statistics.py b/app/service/statistics.py index 40b3268f1..b9cd985f2 100644 --- a/app/service/statistics.py +++ b/app/service/statistics.py @@ -16,7 +16,7 @@ def format_statistics(statistics): def format_monthly_template_notification_stats(year, rows): - dict = { + stats = { datetime.strftime(date, '%Y-%m'): {} for date in [ datetime(year, month, 1) for month in range(4, 13) @@ -27,14 +27,15 @@ def format_monthly_template_notification_stats(year, rows): for row in rows: formatted_month = row.month.strftime('%Y-%m') - if str(row.template_id) not in dict[formatted_month]: - dict[formatted_month][str(row.template_id)] = { + if str(row.template_id) not in stats[formatted_month]: + stats[formatted_month][str(row.template_id)] = { "name": row.name, + "type": row.template_type, "counts": dict.fromkeys(NOTIFICATION_STATUS_TYPES, 0) } - dict[formatted_month][str(row.template_id)]["counts"][row.status] += row.count + stats[formatted_month][str(row.template_id)]["counts"][row.status] += row.count - return dict + return stats def create_zeroed_stats_dicts(): diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index 4cfd0b040..f3195ce52 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -57,6 +57,7 @@ from tests.app.conftest import ( def test_should_have_decorated_services_dao_functions(): + assert dao_fetch_monthly_historical_stats_by_template_for_service.__wrapped__.__name__ == 'dao_fetch_monthly_historical_stats_by_template_for_service' # noqa assert dao_fetch_monthly_historical_stats_for_service.__wrapped__.__name__ == 'dao_fetch_monthly_historical_stats_for_service' # noqa assert dao_fetch_todays_stats_for_service.__wrapped__.__name__ == 'dao_fetch_todays_stats_for_service' # noqa assert dao_fetch_stats_for_service.__wrapped__.__name__ == 'dao_fetch_stats_for_service' # noqa diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index c4e68a1e6..2b8c0b23d 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -1477,6 +1477,8 @@ def test_get_template_stats_by_month_returns_correct_data(notify_db, notify_db_s resp_json = json.loads(resp.get_data(as_text=True)).get('data') assert resp.status_code == 200 + assert resp_json["2016-05"][str(sample_template.id)]["name"] == "Template Name" + assert resp_json["2016-05"][str(sample_template.id)]["type"] == "sms" assert resp_json["2016-05"][str(sample_template.id)]["counts"]["sending"] == 2 assert resp_json["2016-05"][str(sample_template.id)]["counts"]["temporary-failure"] == 1 assert resp_json["2016-05"][str(sample_template.id)]["counts"]["permanent-failure"] == 1