Use a ModelList for lists of jobs

This follows the pattern of what we’ve done with services, users and
events.

It gives us a way of neatly instantiating a model for each item in the
list we get back from the API and reduces the complexity of the view
layer code.

Now is a good time to do this because we’re going to be making a bunch
of changes to the jobs pages, and those changes will be easier to code
and understand with a sensible model behind them.
This commit is contained in:
Chris Hill-Scott
2020-01-08 14:29:56 +00:00
parent 5e7ec3e30d
commit 25464a141b
13 changed files with 106 additions and 76 deletions

View File

@@ -1,7 +1,7 @@
import pytest
from app.models.job import Job
from app.statistics_utils import (
add_rate_to_job,
add_rates_to,
statistics_by_state,
sum_of_statistics,
@@ -128,7 +128,7 @@ def test_service_statistics_by_state():
(1, 4, 20)
])
def test_add_rate_to_job_calculates_rate(failed, delivered, expected_failure_rate):
resp = add_rate_to_job(
resp = Job(
{
'notifications_failed': failed,
'notifications_delivered': delivered,
@@ -136,11 +136,11 @@ def test_add_rate_to_job_calculates_rate(failed, delivered, expected_failure_rat
}
)
assert resp['failure_rate'] == expected_failure_rate
assert resp.failure_rate == expected_failure_rate
def test_add_rate_to_job_preserves_initial_fields():
resp = add_rate_to_job(
resp = Job(
{
'notifications_failed': 0,
'notifications_delivered': 0,
@@ -148,4 +148,5 @@ def test_add_rate_to_job_preserves_initial_fields():
}
)
assert set(resp.keys()) == {'notifications_failed', 'notifications_delivered', 'id', 'failure_rate'}
assert resp.notifications_failed == resp.notifications_delivered == resp.failure_rate == 0
assert resp.id == 'foo'