mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-05 20:18:24 -04:00
Fix for admin app to show job data on dashboard page
- uses the new stats block in the API to build the stats expected by the dashboard page - all work done in client
This commit is contained in:
@@ -21,8 +21,8 @@ class JobApiClient(BaseAPIClient):
|
|||||||
'delivered': 0,
|
'delivered': 0,
|
||||||
'failed': 0
|
'failed': 0
|
||||||
}
|
}
|
||||||
if 'statistics' in job['data']:
|
if 'statistics' in job:
|
||||||
for outcome in job['data']['statistics']:
|
for outcome in job['statistics']:
|
||||||
if outcome['status'] in ['failed', 'technical-failure', 'temporary-failure', 'permanent-failure']:
|
if outcome['status'] in ['failed', 'technical-failure', 'temporary-failure', 'permanent-failure']:
|
||||||
results['failed'] += outcome['count']
|
results['failed'] += outcome['count']
|
||||||
if outcome['status'] in ['sending', 'pending', 'created']:
|
if outcome['status'] in ['sending', 'pending', 'created']:
|
||||||
@@ -38,7 +38,7 @@ class JobApiClient(BaseAPIClient):
|
|||||||
params['status'] = status
|
params['status'] = status
|
||||||
job = self.get(url='/service/{}/job/{}'.format(service_id, job_id), params=params)
|
job = self.get(url='/service/{}/job/{}'.format(service_id, job_id), params=params)
|
||||||
if 'notifications_sent' not in job['data']:
|
if 'notifications_sent' not in job['data']:
|
||||||
stats = self.__convert_statistics(job)
|
stats = self.__convert_statistics(job['data'])
|
||||||
job['data']['notifications_sent'] = stats['delivered'] + stats['failed']
|
job['data']['notifications_sent'] = stats['delivered'] + stats['failed']
|
||||||
job['data']['notifications_delivered'] = stats['delivered']
|
job['data']['notifications_delivered'] = stats['delivered']
|
||||||
job['data']['notifications_failed'] = stats['failed']
|
job['data']['notifications_failed'] = stats['failed']
|
||||||
@@ -48,7 +48,15 @@ class JobApiClient(BaseAPIClient):
|
|||||||
if limit_days is not None:
|
if limit_days is not None:
|
||||||
params['limit_days'] = limit_days
|
params['limit_days'] = limit_days
|
||||||
|
|
||||||
return self.get(url='/service/{}/job'.format(service_id), params=params)
|
jobs = self.get(url='/service/{}/job'.format(service_id), params=params)
|
||||||
|
for job in jobs['data']:
|
||||||
|
if 'notifications_sent' not in job:
|
||||||
|
stats = self.__convert_statistics(job)
|
||||||
|
job['notifications_sent'] = stats['delivered'] + stats['failed']
|
||||||
|
job['notifications_delivered'] = stats['delivered']
|
||||||
|
job['notifications_failed'] = stats['failed']
|
||||||
|
|
||||||
|
return jobs
|
||||||
|
|
||||||
def create_job(self, job_id, service_id, template_id, original_file_name, notification_count):
|
def create_job(self, job_id, service_id, template_id, original_file_name, notification_count):
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
@@ -157,3 +157,81 @@ def test_client_parses_job_stats(mocker):
|
|||||||
assert result['data']['notifications_sent'] == 50
|
assert result['data']['notifications_sent'] == 50
|
||||||
assert result['data']['notification_count'] == 80
|
assert result['data']['notification_count'] == 80
|
||||||
assert result['data']['notifications_failed'] == 40
|
assert result['data']['notifications_failed'] == 40
|
||||||
|
|
||||||
|
|
||||||
|
def test_client_parses_job_stats_for_service(mocker):
|
||||||
|
mocker.patch('app.notify_client.current_user', id='1')
|
||||||
|
|
||||||
|
service_id = 'service_id'
|
||||||
|
job_1_id = 'job_id_1'
|
||||||
|
job_2_id = 'job_id_2'
|
||||||
|
expected_data = {'data': [{
|
||||||
|
'status': 'finished',
|
||||||
|
'template_version': 3,
|
||||||
|
'id': job_1_id,
|
||||||
|
'updated_at': '2016-08-24T08:29:28.332972+00:00',
|
||||||
|
'service': service_id,
|
||||||
|
'processing_finished': '2016-08-24T08:11:48.676365+00:00',
|
||||||
|
'statistics': [
|
||||||
|
{'status': 'failed', 'count': 10},
|
||||||
|
{'status': 'technical-failure', 'count': 10},
|
||||||
|
{'status': 'temporary-failure', 'count': 10},
|
||||||
|
{'status': 'permanent-failure', 'count': 10},
|
||||||
|
{'status': 'created', 'count': 10},
|
||||||
|
{'status': 'sending', 'count': 10},
|
||||||
|
{'status': 'pending', 'count': 10},
|
||||||
|
{'status': 'delivered', 'count': 10}
|
||||||
|
],
|
||||||
|
'original_file_name': 'test-notify-email.csv',
|
||||||
|
'created_by': {
|
||||||
|
'name': 'test-user@digital.cabinet-office.gov.uk',
|
||||||
|
'id': '3571f2ae-7a39-4fb4-9ad7-8453f5257072'
|
||||||
|
},
|
||||||
|
'created_at': '2016-08-24T08:09:56.371073+00:00',
|
||||||
|
'template': 'c0309261-9c9e-4530-8fed-5f67b02260d2',
|
||||||
|
'notification_count': 80,
|
||||||
|
'processing_started': '2016-08-24T08:09:57.661246+00:00'
|
||||||
|
}, {
|
||||||
|
'status': 'finished',
|
||||||
|
'template_version': 3,
|
||||||
|
'id': job_2_id,
|
||||||
|
'updated_at': '2016-08-24T08:29:28.332972+00:00',
|
||||||
|
'service': service_id,
|
||||||
|
'processing_finished': '2016-08-24T08:11:48.676365+00:00',
|
||||||
|
'statistics': [
|
||||||
|
{'status': 'failed', 'count': 5},
|
||||||
|
{'status': 'technical-failure', 'count': 5},
|
||||||
|
{'status': 'temporary-failure', 'count': 5},
|
||||||
|
{'status': 'permanent-failure', 'count': 5},
|
||||||
|
{'status': 'created', 'count': 5},
|
||||||
|
{'status': 'sending', 'count': 5},
|
||||||
|
{'status': 'pending', 'count': 5},
|
||||||
|
{'status': 'delivered', 'count': 5}
|
||||||
|
],
|
||||||
|
'original_file_name': 'test-notify-email.csv',
|
||||||
|
'created_by': {
|
||||||
|
'name': 'test-user@digital.cabinet-office.gov.uk',
|
||||||
|
'id': '3571f2ae-7a39-4fb4-9ad7-8453f5257072'
|
||||||
|
},
|
||||||
|
'created_at': '2016-08-24T08:09:56.371073+00:00',
|
||||||
|
'template': 'c0309261-9c9e-4530-8fed-5f67b02260d2',
|
||||||
|
'notification_count': 40,
|
||||||
|
'processing_started': '2016-08-24T08:09:57.661246+00:00'
|
||||||
|
}]}
|
||||||
|
|
||||||
|
expected_url = '/service/{}/job'.format(service_id)
|
||||||
|
|
||||||
|
client = JobApiClient()
|
||||||
|
mock_get = mocker.patch('app.notify_client.job_api_client.JobApiClient.get', return_value=expected_data)
|
||||||
|
|
||||||
|
result = client.get_job(service_id)
|
||||||
|
|
||||||
|
mock_get.assert_called_once_with(url=expected_url, params={})
|
||||||
|
assert result['data'][0]['id'] == job_1_id
|
||||||
|
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_sent'] == 25
|
||||||
|
assert result['data'][1]['notification_count'] == 40
|
||||||
|
assert result['data'][1]['notifications_failed'] == 20
|
||||||
|
|||||||
Reference in New Issue
Block a user