mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
As job update is a PUT then all non nullable fields
need to be sent with update. Also bug in not committing update fixed.
This commit is contained in:
@@ -4,13 +4,13 @@ from app.models import Job
|
|||||||
|
|
||||||
def save_job(job, update_dict={}):
|
def save_job(job, update_dict={}):
|
||||||
if update_dict:
|
if update_dict:
|
||||||
update_dict.pop('id')
|
update_dict.pop('id', None)
|
||||||
update_dict.pop('service')
|
update_dict.pop('service', None)
|
||||||
update_dict.pop('template')
|
update_dict.pop('template', None)
|
||||||
Job.query.filter_by(id=job.id).update(update_dict)
|
Job.query.filter_by(id=job.id).update(update_dict)
|
||||||
else:
|
else:
|
||||||
db.session.add(job)
|
db.session.add(job)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def get_job(service_id, job_id):
|
def get_job(service_id, job_id):
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ def create_job(service_id):
|
|||||||
|
|
||||||
@job.route('/<job_id>', methods=['PUT'])
|
@job.route('/<job_id>', methods=['PUT'])
|
||||||
def update_job(service_id, job_id):
|
def update_job(service_id, job_id):
|
||||||
|
|
||||||
job = get_job(service_id, job_id)
|
job = get_job(service_id, job_id)
|
||||||
update_dict, errors = job_schema_load_json.load(request.get_json())
|
update_dict, errors = job_schema_load_json.load(request.get_json())
|
||||||
if errors:
|
if errors:
|
||||||
@@ -77,14 +78,19 @@ def _enqueue_job(job):
|
|||||||
|
|
||||||
queue = boto3.resource('sqs', region_name=aws_region).create_queue(QueueName=queue_name)
|
queue = boto3.resource('sqs', region_name=aws_region).create_queue(QueueName=queue_name)
|
||||||
data = {
|
data = {
|
||||||
'job_id': str(job.id),
|
'id': str(job.id),
|
||||||
'service_id': str(job.service.id),
|
'service_id': str(job.service.id),
|
||||||
'template_id': job.template_id,
|
'template_id': job.template.id,
|
||||||
'bucket_name': job.bucket_name
|
'bucket_name': job.bucket_name,
|
||||||
|
'file_name': job.file_name,
|
||||||
|
'original_file_name': job.original_file_name
|
||||||
}
|
}
|
||||||
job_json = json.dumps(data)
|
job_json = json.dumps(data)
|
||||||
queue.send_message(MessageBody=job_json,
|
queue.send_message(MessageBody=job_json,
|
||||||
MessageAttributes={'job_id': {'StringValue': str(job.id), 'DataType': 'String'},
|
MessageAttributes={'id': {'StringValue': str(job.id), 'DataType': 'String'},
|
||||||
'service_id': {'StringValue': str(job.service.id), 'DataType': 'String'},
|
'service': {'StringValue': str(job.service.id), 'DataType': 'String'},
|
||||||
'template_id': {'StringValue': str(job.template_id), 'DataType': 'Number'},
|
'template': {'StringValue': str(job.template.id), 'DataType': 'String'},
|
||||||
'bucket_name': {'StringValue': job.bucket_name, 'DataType': 'String'}})
|
'bucket_name': {'StringValue': job.bucket_name, 'DataType': 'String'},
|
||||||
|
'file_name': {'StringValue': job.file_name, 'DataType': 'String'},
|
||||||
|
'original_file_name': {'StringValue': job.original_file_name,
|
||||||
|
'DataType': 'String'}})
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ def test_create_job(notify_api, notify_db, notify_db_session, sample_template):
|
|||||||
assert len(messages) == 1
|
assert len(messages) == 1
|
||||||
|
|
||||||
expected_message = json.loads(messages[0].body)
|
expected_message = json.loads(messages[0].body)
|
||||||
assert expected_message['job_id'] == str(job_id)
|
assert expected_message['id'] == str(job_id)
|
||||||
assert expected_message['service_id'] == str(service_id)
|
assert expected_message['service_id'] == str(service_id)
|
||||||
assert expected_message['template_id'] == template_id
|
assert expected_message['template_id'] == template_id
|
||||||
assert expected_message['bucket_name'] == bucket_name
|
assert expected_message['bucket_name'] == bucket_name
|
||||||
|
|||||||
Reference in New Issue
Block a user