From fe64b565a02d1f209e4da511fe39bccacf029c9f Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 31 Jan 2017 11:11:33 +0000 Subject: [PATCH] Create job now checks that the service is active before creating job. Need to check what message and status code we should use for this case. Probably will create a InactiveServiceRequest exception. --- app/config.py | 2 +- app/job/rest.py | 4 +++- tests/app/job/test_rest.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/config.py b/app/config.py index 1b4164482..fc9a9dd23 100644 --- a/app/config.py +++ b/app/config.py @@ -203,7 +203,7 @@ class Test(Config): Queue('send-email', Exchange('default'), routing_key='send-email'), Queue('research-mode', Exchange('default'), routing_key='research-mode') ] - REDIS_ENABLED = True + REDIS_ENABLED = False API_HOST_NAME = "http://localhost:6011" diff --git a/app/job/rest.py b/app/job/rest.py index 3a8a60219..bf6692396 100644 --- a/app/job/rest.py +++ b/app/job/rest.py @@ -110,7 +110,9 @@ def get_jobs_by_service(service_id): @job.route('', methods=['POST']) def create_job(service_id): - dao_fetch_service_by_id(service_id) + service = dao_fetch_service_by_id(service_id) + if not service.active: + raise InvalidRequest("Unable to create job to inactive service", 400) data = request.get_json() diff --git a/tests/app/job/test_rest.py b/tests/app/job/test_rest.py index de7405289..908504553 100644 --- a/tests/app/job/test_rest.py +++ b/tests/app/job/test_rest.py @@ -170,6 +170,18 @@ def test_create_scheduled_job(notify_api, sample_template, mocker, fake_uuid): assert resp_json['data']['original_file_name'] == 'thisisatest.csv' +def test_create_job_returns_400_if_service_is_not_active(client, fake_uuid, sample_service, mocker): + sample_service.active = False + mock_job_dao = mocker.patch("app.dao.jobs_dao.dao_create_job") + auth_header = create_authorization_header() + response = client.post('/service/{}/job'.format(sample_service.id), + data="", + headers=[('Content-Type', 'application/json'), auth_header]) + + assert response.status_code == 400 + mock_job_dao.assert_not_called() + + def test_should_not_create_scheduled_job_more_then_24_hours_hence(notify_api, sample_template, mocker, fake_uuid): with notify_api.test_request_context(): with notify_api.test_client() as client: