From 7324b30dbc6d3d1fa0c13569194ab92ba439c786 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 30 Aug 2016 14:50:38 +0100 Subject: [PATCH] Re-add a 'requested' stat to a job MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s useful to know how many notifications we’ve handed off to our providers. This is a measure of how complete the processing of the job is. This is important, because once the job processing is complete then you can accurately reconcile the report with the CSV file that you’ve uploaded. --- app/notify_client/job_api_client.py | 6 +++++- tests/app/notify_client/test_job_client.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/notify_client/job_api_client.py b/app/notify_client/job_api_client.py index ddd08ad9b..dc3250ef4 100644 --- a/app/notify_client/job_api_client.py +++ b/app/notify_client/job_api_client.py @@ -19,7 +19,8 @@ class JobApiClient(BaseAPIClient): results = { 'sending': 0, 'delivered': 0, - 'failed': 0 + 'failed': 0, + 'requested': 0 } if 'statistics' in job: for outcome in job['statistics']: @@ -29,6 +30,7 @@ class JobApiClient(BaseAPIClient): 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): @@ -42,6 +44,7 @@ class JobApiClient(BaseAPIClient): job['data']['notifications_sent'] = stats['delivered'] + stats['failed'] job['data']['notifications_delivered'] = stats['delivered'] job['data']['notifications_failed'] = stats['failed'] + job['data']['notifications_requested'] = stats['requested'] return job params = {} @@ -55,6 +58,7 @@ class JobApiClient(BaseAPIClient): job['notifications_sent'] = stats['delivered'] + stats['failed'] job['notifications_delivered'] = stats['delivered'] job['notifications_failed'] = stats['failed'] + job['notifications_requested'] = stats['requested'] return jobs diff --git a/tests/app/notify_client/test_job_client.py b/tests/app/notify_client/test_job_client.py index a6ba9c937..5009c7c6a 100644 --- a/tests/app/notify_client/test_job_client.py +++ b/tests/app/notify_client/test_job_client.py @@ -154,6 +154,7 @@ def test_client_parses_job_stats(mocker): result = client.get_job(service_id, job_id) mock_get.assert_called_once_with(url=expected_url, params={}) + assert result['data']['notifications_requested'] == 80 assert result['data']['notifications_sent'] == 50 assert result['data']['notification_count'] == 80 assert result['data']['notifications_failed'] == 40 @@ -191,6 +192,7 @@ def test_client_parses_empty_job_stats(mocker): result = client.get_job(service_id, job_id) mock_get.assert_called_once_with(url=expected_url, params={}) + assert result['data']['notifications_requested'] == 0 assert result['data']['notifications_sent'] == 0 assert result['data']['notification_count'] == 80 assert result['data']['notifications_failed'] == 0 @@ -265,10 +267,12 @@ def test_client_parses_job_stats_for_service(mocker): mock_get.assert_called_once_with(url=expected_url, params={}) assert result['data'][0]['id'] == job_1_id + assert result['data'][0]['notifications_requested'] == 80 assert result['data'][0]['notifications_sent'] == 50 assert result['data'][0]['notification_count'] == 80 assert result['data'][0]['notifications_failed'] == 40 assert result['data'][1]['id'] == job_2_id + assert result['data'][1]['notifications_requested'] == 40 assert result['data'][1]['notifications_sent'] == 25 assert result['data'][1]['notification_count'] == 40 assert result['data'][1]['notifications_failed'] == 20 @@ -325,10 +329,12 @@ def test_client_parses_empty_job_stats_for_service(mocker): mock_get.assert_called_once_with(url=expected_url, params={}) assert result['data'][0]['id'] == job_1_id + assert result['data'][0]['notifications_requested'] == 0 assert result['data'][0]['notifications_sent'] == 0 assert result['data'][0]['notification_count'] == 80 assert result['data'][0]['notifications_failed'] == 0 assert result['data'][1]['id'] == job_2_id + assert result['data'][1]['notifications_requested'] == 0 assert result['data'][1]['notifications_sent'] == 0 assert result['data'][1]['notification_count'] == 40 assert result['data'][1]['notifications_failed'] == 0