From fa4fd1c8969dd5412598f1843a317df02a085656 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 17 Jan 2020 10:01:39 +0000 Subject: [PATCH] Account for missing scheduled for field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jobs have a `scheduled_for` field. Single letter uploads don’t. At the moment we treat both of them as `Job`s. So the `Job` model needs to account for when the `scheduled_for` field is missing. --- app/models/job.py | 5 ++++- tests/conftest.py | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/job.py b/app/models/job.py index 2b1eb4597..855aa1ce8 100644 --- a/app/models/job.py +++ b/app/models/job.py @@ -26,7 +26,6 @@ class Job(JSONModel): 'notification_count', 'job_status', 'created_by', - 'scheduled_for', } @classmethod @@ -45,6 +44,10 @@ class Job(JSONModel): def scheduled(self): return self.status == 'scheduled' + @property + def scheduled_for(self): + return self._dict.get('scheduled_for') + def _aggregate_statistics(self, *statuses): return sum( outcome['count'] for outcome in self._dict['statistics'] diff --git a/tests/conftest.py b/tests/conftest.py index f6043b141..9a937fcfb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1732,7 +1732,6 @@ def mock_get_uploads(mocker, api_user_active): 'notification_count': 10, 'created_at': '2016-01-01 11:09:00.061258', 'statistics': [{'count': 8, 'status': 'delivered'}, {'count': 2, 'status': 'temporary-failure'}], - 'scheduled_for': None, 'job_status': 'finished', 'upload_type': 'job'}, {'id': 'job_id_1', @@ -1740,7 +1739,6 @@ def mock_get_uploads(mocker, api_user_active): 'notification_count': 1, 'created_at': '2016-01-01 11:09:00.061258', 'statistics': [{'count': 1, 'status': 'delivered'}], - 'scheduled_for': None, 'job_status': 'finished', 'upload_type': 'letter'} ]