Use default dict for default job stats

This is just some refactoring.

`defaultdict` is a data structure which won’t raise a `KeyError` if you
try to access a key that doesn’t exist.

By passing `int` as the first argument, trying to access the value of
any key that doesn’t exists will return the value of `int()`, ie `0`
This commit is contained in:
Chris Hill-Scott
2016-08-30 14:54:33 +01:00
parent 7324b30dbc
commit 37a1eb22b0

View File

@@ -1,3 +1,4 @@
from collections import defaultdict
from notifications_python_client.base import BaseAPIClient
from app.notify_client import _attach_current_user
@@ -16,12 +17,7 @@ class JobApiClient(BaseAPIClient):
@staticmethod
def __convert_statistics(job):
results = {
'sending': 0,
'delivered': 0,
'failed': 0,
'requested': 0
}
results = defaultdict(int)
if 'statistics' in job:
for outcome in job['statistics']:
if outcome['status'] in ['failed', 'technical-failure', 'temporary-failure', 'permanent-failure']: