diff --git a/app/job/rest.py b/app/job/rest.py index e5ce149fe..cde9c2b11 100644 --- a/app/job/rest.py +++ b/app/job/rest.py @@ -141,7 +141,6 @@ def create_job(service_id): raise InvalidRequest("Create job is not allowed: service is inactive ", 403) data = request.get_json() - data.update({ "service": service_id }) diff --git a/app/schemas.py b/app/schemas.py index 5dd616617..e53782b04 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -381,6 +381,7 @@ class JobSchema(BaseSchema): ServiceSchema, attribute="service", dump_to="service_name", only=["name"], dump_only=True) template_type = fields.Method('get_template_type', dump_only=True) + contact_list_id = field_for(models.Job, 'contact_list_id') def get_template_type(self, job): return job.template.template_type diff --git a/tests/app/job/test_rest.py b/tests/app/job/test_rest.py index e9141aa98..4ddb50d6f 100644 --- a/tests/app/job/test_rest.py +++ b/tests/app/job/test_rest.py @@ -13,7 +13,12 @@ from app.models import JOB_STATUS_TYPES, JOB_STATUS_PENDING from tests import create_authorization_header from tests.conftest import set_config -from tests.app.db import create_ft_notification_status, create_job, create_notification +from tests.app.db import ( + create_ft_notification_status, + create_job, + create_notification, + create_service_contact_list +) def test_get_job_with_invalid_service_id_returns404(client, sample_service): @@ -233,6 +238,30 @@ def test_create_scheduled_job(client, sample_template, mocker, fake_uuid): assert resp_json['data']['notification_count'] == 1 +def test_create_job_with_contact_list_id(client, mocker, sample_template, fake_uuid): + mocker.patch('app.celery.tasks.process_job.apply_async') + mocker.patch('app.job.rest.get_job_metadata_from_s3', return_value={ + 'template_id': str(sample_template.id) + }) + contact_list = create_service_contact_list() + data = { + 'id': fake_uuid, + 'valid': 'True', + 'original_file_name': contact_list.original_file_name, + 'created_by': str(sample_template.service.users[0].id), + 'notification_count': 100, + 'contact_list_id': str(contact_list.id), + } + response = client.post( + f'/service/{sample_template.service_id}/job', + data=json.dumps(data), + headers=[('Content-Type', 'application/json'), create_authorization_header()]) + resp_json = response.get_json() + assert response.status_code == 201 + assert resp_json['data']['contact_list_id'] == str(contact_list.id) + assert resp_json['data']['original_file_name'] == 'EmergencyContactList.xls' + + def test_create_job_returns_403_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") @@ -683,6 +712,7 @@ def test_get_jobs(admin_request, sample_template): 'template_type': 'sms', 'template_version': 1, 'updated_at': None, + 'contact_list_id': None }