From 0dfa4a93d5e9bcd7045b7482f571dec5987aa91a Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 7 Feb 2017 13:06:32 +0000 Subject: [PATCH] Make sure status dictionary is assinged each time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The status dictionary was being assigned once, and then subsequent uses of it were by reference. This meant that each template type was pointing at the same dictionary, and updating one meant updating all. This commit adds a dictionary comprehension, which gets evaluated once for each template type, so each template type has its own `dict` of statuses. Before -- ``` Email SMS Letter | | | {'sending':, 'failed', …} ``` After -- ``` Email SMS Letter | | | {'sending':, {'sending':, {'sending':, 'failed', 'failed', 'failed', …} …} …} ``` --- app/dao/services_dao.py | 8 ++++---- tests/app/dao/test_services_dao.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index b9ad66ae9..867f103b3 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -267,13 +267,13 @@ def dao_fetch_monthly_historical_stats_for_service(service_id, year): ) months = { - datetime.strftime(date, '%Y-%m'): dict.fromkeys( - TEMPLATE_TYPES, - dict.fromkeys( + datetime.strftime(date, '%Y-%m'): { + template_type: dict.fromkeys( NOTIFICATION_STATUS_TYPES, 0 ) - ) + for template_type in TEMPLATE_TYPES + } for date in [ datetime(year, month, 1) for month in range(4, 13) ] + [ diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index af72342d0..6e4afa8b3 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -545,8 +545,8 @@ def test_fetch_monthly_historical_stats_separates_weeks(notify_db, notify_db_ses ('2017-03', 'created', 2), ): assert result[date]['sms'][status] == count - assert result[date]['email'][status] == count - assert result[date]['letter'][status] == count + assert result[date]['email'][status] == 0 + assert result[date]['letter'][status] == 0 assert result.keys() == { '2016-04', '2016-05', '2016-06',