Fixes modify workflow method

This commit is contained in:
Aaron Louie 2020-01-21 15:24:17 -05:00
parent c11bf3d286
commit 6158243053
2 changed files with 11 additions and 13 deletions

View File

@ -1,7 +1,7 @@
import uuid import uuid
from crc.api.common import ApiError, ApiErrorSchema
from crc import session from crc import session
from crc.api.common import ApiError, ApiErrorSchema
from crc.models.workflow import WorkflowModel, WorkflowModelSchema, WorkflowSpecModelSchema, WorkflowSpecModel, \ from crc.models.workflow import WorkflowModel, WorkflowModelSchema, WorkflowSpecModelSchema, WorkflowSpecModel, \
Task, TaskSchema Task, TaskSchema
from crc.workflow_processor import WorkflowProcessor from crc.workflow_processor import WorkflowProcessor
@ -20,26 +20,20 @@ def add_workflow_specification(body):
def update_workflow_specification(spec_id, body): def update_workflow_specification(spec_id, body):
if spec_id is None: if spec_id is None:
error = ApiError('unknown_study', 'Please provide a valid Workflow Specification ID.') error = ApiError('unknown_study', 'Please provide a valid Workflow Specification ID.')
return ApiErrorSchema.dump(error), 404 return ApiErrorSchema.dump(error), 404
db_spec = session.query(WorkflowSpecModel).filter_by(id=spec_id).first() spec: WorkflowSpecModel = session.query(WorkflowSpecModel).filter_by(id=spec_id).first()
""":type: WorkflowSpecModel"""
if db_spec is None: if spec is None:
error = ApiError('unknown_study', 'The Workflow Specification "' + spec_id + '" is not recognized.') error = ApiError('unknown_study', 'The Workflow Specification "' + spec_id + '" is not recognized.')
return ApiErrorSchema.dump(error), 404 return ApiErrorSchema.dump(error), 404
new_spec = WorkflowSpecModelSchema().load(body, session=session) spec = WorkflowSpecModelSchema().load(body, session=session)
""":type: WorkflowSpecModel""" session.add(spec)
db_spec.id = new_spec.id
db_spec.display_name = new_spec.display_name
db_spec.description = new_spec.description
session.commit() session.commit()
return WorkflowSpecModelSchema().dump(db_spec) return WorkflowSpecModelSchema().dump(spec)
def get_workflow(workflow_id): def get_workflow(workflow_id):

View File

@ -103,7 +103,7 @@ class TestStudy(BaseTest, unittest.TestCase):
def test_modify_workflow_specification(self): def test_modify_workflow_specification(self):
self.load_example_data() self.load_example_data()
old_id = 'random_fact' old_id = 'random_fact'
spec = session.query(WorkflowSpecModel).filter_by(id=old_id).first() spec: WorkflowSpecModel = session.query(WorkflowSpecModel).filter_by(id=old_id).first()
""":type: WorkflowSpecModel""" """:type: WorkflowSpecModel"""
spec.id = 'odd_datum' spec.id = 'odd_datum'
@ -114,6 +114,10 @@ class TestStudy(BaseTest, unittest.TestCase):
self.assert_success(rv) self.assert_success(rv)
db_spec = session.query(WorkflowSpecModel).filter_by(id=spec.id).first() db_spec = session.query(WorkflowSpecModel).filter_by(id=spec.id).first()
self.assertEqual(spec.display_name, db_spec.display_name) self.assertEqual(spec.display_name, db_spec.display_name)
num_old_after = session.query(WorkflowSpecModel).filter_by(id=old_id).count()
self.assertEqual(num_old_after, 0)
num_after = session.query(WorkflowSpecModel).count() num_after = session.query(WorkflowSpecModel).count()
self.assertEqual(num_after, num_before) self.assertEqual(num_after, num_before)