mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-08 01:58:26 -04:00
Merge pull request #2754 from alphagov/update-jobs-contact_list_id
Update jobs contact list
This commit is contained in:
@@ -141,7 +141,6 @@ def create_job(service_id):
|
|||||||
raise InvalidRequest("Create job is not allowed: service is inactive ", 403)
|
raise InvalidRequest("Create job is not allowed: service is inactive ", 403)
|
||||||
|
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
|
||||||
data.update({
|
data.update({
|
||||||
"service": service_id
|
"service": service_id
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -381,6 +381,7 @@ class JobSchema(BaseSchema):
|
|||||||
ServiceSchema, attribute="service", dump_to="service_name", only=["name"], dump_only=True)
|
ServiceSchema, attribute="service", dump_to="service_name", only=["name"], dump_only=True)
|
||||||
|
|
||||||
template_type = fields.Method('get_template_type', 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):
|
def get_template_type(self, job):
|
||||||
return job.template.template_type
|
return job.template.template_type
|
||||||
|
|||||||
@@ -13,7 +13,12 @@ from app.models import JOB_STATUS_TYPES, JOB_STATUS_PENDING
|
|||||||
|
|
||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
from tests.conftest import set_config
|
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):
|
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
|
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):
|
def test_create_job_returns_403_if_service_is_not_active(client, fake_uuid, sample_service, mocker):
|
||||||
sample_service.active = False
|
sample_service.active = False
|
||||||
mock_job_dao = mocker.patch("app.dao.jobs_dao.dao_create_job")
|
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_type': 'sms',
|
||||||
'template_version': 1,
|
'template_version': 1,
|
||||||
'updated_at': None,
|
'updated_at': None,
|
||||||
|
'contact_list_id': None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user