mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-11 07:33:48 -04:00
Merge pull request #919 from alphagov/revert-918-catch-missing-statistics
Revert "Revert "Remove check for statistics not being on job""
This commit is contained in:
@@ -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):
|
||||
@@ -71,9 +70,10 @@ class JobApiClient(BaseAPIClient):
|
||||
job = self.post(url='/service/{}/job'.format(service_id), data=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_delivered'] = stats['delivered']
|
||||
job['data']['notifications_failed'] = stats['failed']
|
||||
job['data']['notifications_requested'] = stats['requested']
|
||||
|
||||
return job
|
||||
|
||||
@@ -20,9 +20,17 @@ def test_client_creates_job_data_correctly(mocker, fake_uuid):
|
||||
expected_url = '/service/{}/job'.format(service_id)
|
||||
|
||||
client = JobApiClient()
|
||||
mock_post = mocker.patch('app.notify_client.job_api_client.JobApiClient.post')
|
||||
mock_post = mocker.patch(
|
||||
'app.notify_client.job_api_client.JobApiClient.post',
|
||||
return_value={'data': dict(statistics=[], **expected_data)}
|
||||
)
|
||||
|
||||
client.create_job(job_id, service_id, template_id, original_file_name, notification_count)
|
||||
result = client.create_job(job_id, service_id, template_id, original_file_name, notification_count)
|
||||
|
||||
assert result['data']['notifications_requested'] == 0
|
||||
assert result['data']['notifications_sent'] == 0
|
||||
assert result['data']['notification_count'] == 1
|
||||
assert result['data']['notifications_failed'] == 0
|
||||
|
||||
mock_post.assert_called_once_with(url=expected_url, data=expected_data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user