From fd480febb49ff96fcdd7ecb1e928582ba191a61b Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 6 Mar 2020 09:40:59 +0000 Subject: [PATCH 1/2] Refactor to use constants for scheduled status Reduces risk of typos, matches what we do for other statuses. --- app/notify_client/job_api_client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/notify_client/job_api_client.py b/app/notify_client/job_api_client.py index 7fa93d52f..81b7cfb12 100644 --- a/app/notify_client/job_api_client.py +++ b/app/notify_client/job_api_client.py @@ -14,8 +14,9 @@ class JobApiClient(NotifyAdminAPIClient): 'ready to send', 'sent to dvla' } - - NON_SCHEDULED_JOB_STATUSES = JOB_STATUSES - {'scheduled', 'cancelled'} + SCHEDULED_JOB_STATUS = 'scheduled' + CANCELLED_JOB_STATUS = 'cancelled' + NON_SCHEDULED_JOB_STATUSES = JOB_STATUSES - {SCHEDULED_JOB_STATUS, CANCELLED_JOB_STATUS} def get_job(self, service_id, job_id): params = {} @@ -65,7 +66,10 @@ class JobApiClient(NotifyAdminAPIClient): def get_scheduled_jobs(self, service_id): return sorted( - self.get_jobs(service_id, statuses=['scheduled'])['data'], + self.get_jobs( + service_id, + statuses=[self.SCHEDULED_JOB_STATUS] + )['data'], key=lambda job: job['scheduled_for'] ) From 3ad00adfb32df00b03000d08bcf144b43bdb403f Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 6 Mar 2020 09:45:02 +0000 Subject: [PATCH 2/2] Reverse chronologically sort scheduled jobs Now that scheduled jobs are mixed in with regular jobs it looks weird for the sort order to be different. This makes the sort order consistently go from furthest in the future to furthest in the past. The old sort order made sense when scheduled jobs were displayed separately on the dashboard. --- app/notify_client/job_api_client.py | 3 ++- app/templates/views/dashboard/_upcoming.html | 2 +- tests/app/main/views/test_jobs.py | 8 ++++---- tests/app/main/views/test_uploads.py | 8 ++++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/notify_client/job_api_client.py b/app/notify_client/job_api_client.py index 81b7cfb12..803bbe26e 100644 --- a/app/notify_client/job_api_client.py +++ b/app/notify_client/job_api_client.py @@ -70,7 +70,8 @@ class JobApiClient(NotifyAdminAPIClient): service_id, statuses=[self.SCHEDULED_JOB_STATUS] )['data'], - key=lambda job: job['scheduled_for'] + key=lambda job: job['scheduled_for'], + reverse=True, ) @cache.set('has_jobs-{service_id}') diff --git a/app/templates/views/dashboard/_upcoming.html b/app/templates/views/dashboard/_upcoming.html index 85dbf4ce3..b0a179230 100644 --- a/app/templates/views/dashboard/_upcoming.html +++ b/app/templates/views/dashboard/_upcoming.html @@ -20,7 +20,7 @@ {% endif %} diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index c17a11a0f..c4ea99aab 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -44,14 +44,14 @@ from tests.conftest import ( ( 'File Messages to be sent' ), - ( - 'send_me_later.csv ' - 'Sending 1 January 2016 at 11:09am 1' - ), ( 'even_later.csv ' 'Sending 1 January 2016 at 11:09pm 1' ), + ( + 'send_me_later.csv ' + 'Sending 1 January 2016 at 11:09am 1' + ), ( 'File Status' ), diff --git a/tests/app/main/views/test_uploads.py b/tests/app/main/views/test_uploads.py index 943e5b205..b62753e77 100644 --- a/tests/app/main/views/test_uploads.py +++ b/tests/app/main/views/test_uploads.py @@ -668,13 +668,13 @@ def test_uploads_page_shows_scheduled_jobs( 'File Status' ), ( - 'send_me_later.csv ' - 'Sending 1 January 2016 at 11:09am ' + 'even_later.csv ' + 'Sending 1 January 2016 at 11:09pm ' '1 text message waiting to send' ), ( - 'even_later.csv ' - 'Sending 1 January 2016 at 11:09pm ' + 'send_me_later.csv ' + 'Sending 1 January 2016 at 11:09am ' '1 text message waiting to send' ), ]