Merge pull request #379 from sartography/top-level-validation-460

Top level validation #460
This commit is contained in:
Dan Funk 2021-09-30 13:11:03 -04:00 committed by GitHub
commit 1251202244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -132,6 +132,13 @@ class WorkflowService(object):
spec, only completing the required fields, rather than everything. spec, only completing the required fields, rather than everything.
""" """
# Get workflow state dictionary, make sure workflow is not disabled.
if validate_study_id is not None:
study_model = session.query(StudyModel).filter(StudyModel.id == validate_study_id).first()
spec_model = session.query(WorkflowSpecModel).filter(WorkflowSpecModel.id == spec_id).first()
status = StudyService._get_study_status(study_model)
if status[spec_model.name]['status'] == 'disabled':
raise ApiError(code='disabled_workflow', message=f"This workflow is disabled. {status[spec_model.name]['message']}")
workflow_model = WorkflowService.make_test_workflow(spec_id, validate_study_id) workflow_model = WorkflowService.make_test_workflow(spec_id, validate_study_id)
try: try:
processor = WorkflowProcessor(workflow_model, validate_only=True) processor = WorkflowProcessor(workflow_model, validate_only=True)

View File

@ -0,0 +1,5 @@
[{
"core_info": {"status": "required", "message": "This workflow is always required and recommended that it is completed after your Protocol Builder entries are done and the Personnel workflow completed"},
"protocol": {"status": "required", "message": "required"},
"data_security_plan": {"status": "disabled", "message": "This is my mocked disable message."}
}]

View File

@ -9,6 +9,7 @@ from tests.base_test import BaseTest
from crc import session, app from crc import session, app
from crc.api.common import ApiErrorSchema from crc.api.common import ApiErrorSchema
from crc.models.protocol_builder import ProtocolBuilderStudySchema from crc.models.protocol_builder import ProtocolBuilderStudySchema
from crc.models.study import StudyModel
from crc.models.workflow import WorkflowSpecModel, WorkflowModel from crc.models.workflow import WorkflowSpecModel, WorkflowModel
from crc.services.workflow_service import WorkflowService from crc.services.workflow_service import WorkflowService
@ -147,3 +148,35 @@ class TestWorkflowSpecValidation(BaseTest):
self.assertIn('enum_with_default', final_data) self.assertIn('enum_with_default', final_data)
self.assertEqual('maybe', final_data['enum_with_default']['value']) self.assertEqual('maybe', final_data['enum_with_default']['value'])
@patch('crc.services.study_service.StudyService._get_study_status')
def test_disabled_spec_validation(self, mock_status):
"""A disabled workflow spec should fail validation"""
app.config['PB_ENABLED'] = True
self.load_example_data()
study_model = session.query(StudyModel).first()
# workflow spec to validate
spec_model = WorkflowSpecModel(id='data_security_plan',
name='data_security_plan',
display_name='Data Security Plan',
description='Data Security Plan',
is_master_spec=False,
category_id=0,
display_order=0,
standalone=False,
library=False)
session.add(spec_model)
session.commit()
# This response sets the status for data_security_plan to disabled
status_response = self.protocol_builder_response('_get_study_status.json')
mock_status.return_value = json.loads(status_response)[0]
# This should raise an ApiError which we can see in the json data
rv = self.app.get('/v1.0/workflow-specification/%s/validate?study_id=%s' % (spec_model.id, study_model.id), headers=self.logged_in_headers())
self.assert_success(rv)
json_data = json.loads(rv.get_data())
self.assertEqual(1, len(json_data))
api_error = json_data[0]
self.assertEqual('disabled_workflow', api_error['code'])
self.assertEqual('This workflow is disabled. This is my mocked disable message.', api_error['message'])