mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-25 00:33:58 -04:00
make add_rate_to_jobs singular
there was no reason for it to operate on a whole list at a time
This commit is contained in:
@@ -38,10 +38,12 @@ class JobApiClient(BaseAPIClient):
|
|||||||
|
|
||||||
return job
|
return job
|
||||||
|
|
||||||
def get_jobs(self, service_id, limit_days=None):
|
def get_jobs(self, service_id, limit_days=None, statuses=None):
|
||||||
params = {}
|
params = {}
|
||||||
if limit_days is not None:
|
if limit_days is not None:
|
||||||
params['limit_days'] = limit_days
|
params['limit_days'] = limit_days
|
||||||
|
if statuses is not None:
|
||||||
|
params['statuses'] = ','.join(statuses)
|
||||||
|
|
||||||
jobs = 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']:
|
for job in jobs['data']:
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ def get_failure_rate_for_job(job):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def add_rate_to_jobs(jobs):
|
def add_rate_to_job(job):
|
||||||
return [dict(
|
return dict(
|
||||||
failure_rate=(get_failure_rate_for_job(job)) * 100,
|
failure_rate=(get_failure_rate_for_job(job)) * 100,
|
||||||
**job
|
**job
|
||||||
) for job in jobs]
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from app.statistics_utils import sum_of_statistics, add_rates_to, add_rate_to_jobs, statistics_by_state
|
from app.statistics_utils import sum_of_statistics, add_rates_to, add_rate_to_job, statistics_by_state
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('delivery_statistics', [
|
@pytest.mark.parametrize('delivery_statistics', [
|
||||||
@@ -118,20 +118,29 @@ def test_service_statistics_by_state():
|
|||||||
@pytest.mark.parametrize('failed, delivered, expected_failure_rate', [
|
@pytest.mark.parametrize('failed, delivered, expected_failure_rate', [
|
||||||
(0, 0, 0),
|
(0, 0, 0),
|
||||||
(0, 1, 0),
|
(0, 1, 0),
|
||||||
|
(1, 1, 50),
|
||||||
(1, 0, 100),
|
(1, 0, 100),
|
||||||
(1, 4, 20)
|
(1, 4, 20)
|
||||||
])
|
])
|
||||||
def test_add_rate_to_jobs(failed, delivered, expected_failure_rate):
|
def test_add_rate_to_job_calculates_rate(failed, delivered, expected_failure_rate):
|
||||||
resp = add_rate_to_jobs([
|
resp = add_rate_to_job(
|
||||||
{
|
{
|
||||||
'notifications_failed': failed,
|
'notifications_failed': failed,
|
||||||
'notifications_delivered': delivered
|
'notifications_delivered': delivered,
|
||||||
},
|
'id': 'foo'
|
||||||
{
|
|
||||||
'notifications_failed': 1,
|
|
||||||
'notifications_delivered': 1
|
|
||||||
}
|
}
|
||||||
])
|
)
|
||||||
|
|
||||||
assert resp[0]['failure_rate'] == expected_failure_rate
|
assert resp['failure_rate'] == expected_failure_rate
|
||||||
assert resp[1]['failure_rate'] == 50
|
|
||||||
|
|
||||||
|
def test_add_rate_to_job_preserves_initial_fields():
|
||||||
|
resp = add_rate_to_job(
|
||||||
|
{
|
||||||
|
'notifications_failed': 0,
|
||||||
|
'notifications_delivered': 0,
|
||||||
|
'id': 'foo'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert set(resp.keys()) == {'notifications_failed', 'notifications_delivered', 'id', 'failure_rate'}
|
||||||
|
|||||||
Reference in New Issue
Block a user