Sort scheduled jobs so soonest is first

The scheduled job you probably care about the most is the soonest –
irrespective of when you scheduled it.
This commit is contained in:
Chris Hill-Scott
2016-08-31 16:50:45 +01:00
parent 72f92b5249
commit 6921d8b59e
3 changed files with 8 additions and 4 deletions

View File

@@ -116,9 +116,9 @@ def get_dashboard_partials(service_id):
job for job in job_api_client.get_job(service_id, limit_days=7)['data']
if job['original_file_name'] != current_app.config['TEST_MESSAGE_FILENAME']
])
scheduled_jobs = [
scheduled_jobs = sorted([
job for job in jobs if job['job_status'] == 'scheduled'
]
], key=lambda job: job['scheduled_for'])
immediate_jobs = [
job for job in jobs if job['job_status'] != 'scheduled'
]

View File

@@ -184,11 +184,14 @@ def test_should_show_upcoming_jobs_on_dashboard(
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
table_rows = page.find_all('tbody')[0].find_all('tr')
assert len(table_rows) == 1
assert len(table_rows) == 2
assert 'send_me_later.csv' in table_rows[0].find_all('th')[0].text
assert 'Sending at 11:09am' in table_rows[0].find_all('th')[0].text
assert table_rows[0].find_all('td')[0].text.strip() == '1'
assert 'even_later.csv' in table_rows[1].find_all('th')[0].text
assert 'Sending at 11:09pm' in table_rows[1].find_all('th')[0].text
assert table_rows[1].find_all('td')[0].text.strip() == '1'
@freeze_time("2016-01-01 11:09:00.061258")

View File

@@ -902,7 +902,8 @@ def mock_get_jobs(mocker, api_user_active):
("all email addresses.xlsx", '', 'pending'),
("applicants.ods", '', ''),
("thisisatest.csv", '', ''),
("send_me_later.csv", '2016-01-01 11:09:00.061258', 'scheduled')
("send_me_later.csv", '2016-01-01 11:09:00.061258', 'scheduled'),
("even_later.csv", '2016-01-01 23:09:00.061258', 'scheduled')
)
]}