From 40e22d8258dc336f52f64b54f78d3912dce48feb Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 31 Aug 2016 10:46:43 +0100 Subject: [PATCH] Remove check for statistics not being on job MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A job will always have statistics. It’s always assigned: https://github.com/alphagov/notifications-api/blob/bcfa83de79e11856f12a7581b6519ec4a66dad36/app/job/rest.py#L48 And the structure should always be the same, even if the counts are zero because they’re generated from this query: https://github.com/alphagov/notifications-api/blob/668e6c9716cfffdb987cbf8abe20c14576864a1c/app/dao/jobs_dao.py#L11-L22 This line suggests that it’s a hangover from the aggregate tables: https://github.com/alphagov/notifications-admin/commit/8c159da3eaf3a8100bdc2603b4addf25b9fe573d#diff-9886486bf41b0680d23588b190c252eaL24 Since it’s no long necessary this commit removes it. --- app/notify_client/job_api_client.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/notify_client/job_api_client.py b/app/notify_client/job_api_client.py index bd9f06d57..10fe9c2f1 100644 --- a/app/notify_client/job_api_client.py +++ b/app/notify_client/job_api_client.py @@ -18,15 +18,14 @@ class JobApiClient(BaseAPIClient): @staticmethod def __convert_statistics(job): results = defaultdict(int) - if 'statistics' in job: - for outcome in job['statistics']: - if outcome['status'] in ['failed', 'technical-failure', 'temporary-failure', 'permanent-failure']: - results['failed'] += outcome['count'] - if outcome['status'] in ['sending', 'pending', 'created']: - results['sending'] += outcome['count'] - if outcome['status'] in ['delivered']: - results['delivered'] += outcome['count'] - results['requested'] += outcome['count'] + for outcome in job['statistics']: + if outcome['status'] in ['failed', 'technical-failure', 'temporary-failure', 'permanent-failure']: + results['failed'] += outcome['count'] + if outcome['status'] in ['sending', 'pending', 'created']: + results['sending'] += outcome['count'] + if outcome['status'] in ['delivered']: + results['delivered'] += outcome['count'] + results['requested'] += outcome['count'] return results def get_job(self, service_id, job_id=None, limit_days=None, status=None):