diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 0d9e139af..fcc45c72c 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -120,7 +120,7 @@ def get_dashboard_partials(service_id): 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' + job for job in jobs if job['job_status'] not in ['scheduled', 'cancelled'] ] service = service_api_client.get_detailed_service(service_id) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index c31d4b70e..dba2cd7fa 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -67,7 +67,7 @@ def view_jobs(service_id): 'views/jobs/jobs.html', jobs=add_rate_to_jobs([ job for job in job_api_client.get_job(service_id)['data'] - if job['job_status'] != 'scheduled' + if job['job_status'] not in ['scheduled', 'cancelled'] ]) ) @@ -78,6 +78,10 @@ def view_jobs(service_id): def view_job(service_id, job_id): job = job_api_client.get_job(service_id, job_id)['data'] + + if job['job_status'] == 'cancelled': + abort(404) + filter_args = _parse_filter_args(request.args) filter_args['status'] = _set_status_filters(filter_args) diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index d3cd0b758..baeba675b 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -149,6 +149,25 @@ def test_should_show_scheduled_job( assert page.find('main').find_all('p')[2].text.strip() == 'Sending will start at midnight' +def test_should_not_show_cancelled_job( + app_, + service_one, + active_user_with_permissions, + mock_get_cancelled_job, + mocker, + fake_uuid +): + with app_.test_request_context(), app_.test_client() as client: + client.login(active_user_with_permissions, mocker, service_one) + response = client.get(url_for( + 'main.view_job', + service_id=service_one['id'], + job_id=fake_uuid + )) + + assert response.status_code == 404 + + def test_should_show_not_show_csv_download_in_tour( app_, service_one, diff --git a/tests/conftest.py b/tests/conftest.py index c71260a6c..c250abdf2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -872,6 +872,20 @@ def mock_get_scheduled_job(mocker, api_user_active): return mocker.patch('app.job_api_client.get_job', side_effect=_get_job) +@pytest.fixture(scope='function') +def mock_get_cancelled_job(mocker, api_user_active): + def _get_job(service_id, job_id): + return {"data": job_json( + service_id, + api_user_active, + job_id=job_id, + job_status='cancelled', + scheduled_for='2016-01-01T00:00:00.061258' + )} + + return mocker.patch('app.job_api_client.get_job', side_effect=_get_job) + + @pytest.fixture(scope='function') def mock_get_job_in_progress(mocker, api_user_active): def _get_job(service_id, job_id): @@ -903,7 +917,8 @@ def mock_get_jobs(mocker, api_user_active): ("applicants.ods", '', ''), ("thisisatest.csv", '', ''), ("send_me_later.csv", '2016-01-01 11:09:00.061258', 'scheduled'), - ("even_later.csv", '2016-01-01 23:09:00.061258', 'scheduled') + ("even_later.csv", '2016-01-01 23:09:00.061258', 'scheduled'), + ("full_of_regret.csv", '2016-01-01 23:09:00.061258', 'cancelled') ) ]}