mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 22:40:31 -04:00
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:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user