Assure we convert to box for validations as well, and test the bloodly snot out of this.

This commit is contained in:
Dan 2021-04-05 12:47:50 -04:00
parent 727aa72e18
commit 501487b31c
3 changed files with 84 additions and 3 deletions

View File

@ -385,8 +385,9 @@ Returns information specific to the protocol.
}
}
if args[0] == 'documents':
return StudyService().get_documents_status(study_id)
return data['study'][args[0]]
return self.box_it(StudyService().get_documents_status(study_id))
return self.box_it(data['study'][args[0]])
# self.add_data_to_task(task=task, data=data["study"])
# self.add_data_to_task(task, {"documents": StudyService().get_documents_status(study_id)})
@ -420,6 +421,9 @@ Returns information specific to the protocol.
if cmd == 'protocol':
retval = StudyService().get_protocol(study_id)
return self.box_it(retval, prefix)
def box_it(self, retval, prefix = None):
if isinstance(retval, list):
return [Box(item) for item in retval]
if isinstance(retval, dict) and prefix is not None:
@ -427,6 +431,7 @@ Returns information specific to the protocol.
elif isinstance(retval, dict):
return Box(retval)
def check_args(self, args, maxlen=1):
if len(args) < 1 or len(args) > maxlen or (args[0] not in StudyInfo.type_options):
raise ApiError(code="missing_argument",

View File

@ -0,0 +1,73 @@
import json
from SpiffWorkflow.bpmn.PythonScriptEngine import Box
from tests.base_test import BaseTest
from unittest.mock import patch
from crc import db, session
from crc.api.common import ApiError
from crc.models.file import FileDataModel, FileModel
from crc.models.protocol_builder import ProtocolBuilderRequiredDocumentSchema, ProtocolBuilderStudySchema
from crc.models.study import StudyModel
from crc.scripts.study_info import StudyInfo
from crc.services.file_service import FileService
from crc.services.study_service import StudyService
from crc.services.workflow_processor import WorkflowProcessor
class TestStudyDetailsScript(BaseTest):
test_uid = "dhf8r"
test_study_id = 1
def setUp(self):
self.load_example_data()
self.create_reference_document()
self.study = session.query(StudyModel).first()
self.workflow_spec_model = self.load_test_spec("two_forms")
self.workflow_model = StudyService._create_workflow_model(self.study, self.workflow_spec_model)
self.processor = WorkflowProcessor(self.workflow_model)
self.task = self.processor.next_task()
def test_study_info_returns_a_box_object_for_all_validations(self):
for option in StudyInfo.type_options:
data = StudyInfo().do_task_validate_only(self.task, self.study.id, self.workflow_model.id, option)
if isinstance(data, list):
for x in data:
self.assertIsInstance(x, Box, "this is not a list of boxes:" + option)
else:
self.assertIsInstance(data, Box, "this is not a box:" + option)
def test_study_info_returns_a_box_object(self):
docs = StudyInfo().do_task(self.task, self.study.id, self.workflow_model.id, "info")
self.assertTrue(isinstance(docs, Box))
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_investigators') # mock_studies
def test_study_investigators_returns_box(self, mock_investigators):
investigators_response = self.protocol_builder_response('investigators.json')
mock_investigators.return_value = json.loads(investigators_response)
docs = StudyInfo().do_task(self.task, self.study.id, self.workflow_model.id, "investigators")
self.assertTrue(isinstance(docs, Box))
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_investigators') # mock_studies
def test_study_roles_returns_box(self, mock_investigators):
investigators_response = self.protocol_builder_response('investigators.json')
mock_investigators.return_value = json.loads(investigators_response)
docs = StudyInfo().do_task(self.task, self.study.id, self.workflow_model.id, "roles")
self.assertTrue(isinstance(docs, Box))
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_studies
def test_study_details_returns_box(self, mock_details):
details_response = self.protocol_builder_response('study_details.json')
mock_details.return_value = json.loads(details_response)
data = StudyInfo().do_task(self.task, self.study.id, self.workflow_model.id, "details")
self.assertTrue(isinstance(data, Box))
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_sponsors') # mock_studies
def test_study_sponsors_returns_box(self, mock):
response = self.protocol_builder_response('sponsors.json')
mock.return_value = json.loads(response)
data = StudyInfo().do_task(self.task, self.study.id, self.workflow_model.id, "sponsors")
self.assertTrue(isinstance(data, list))
for x in data:
self.assertIsInstance(x, Box)

View File

@ -89,4 +89,7 @@ class TestStudyDetailsDocumentsScript(BaseTest):
processor = WorkflowProcessor(workflow_model)
task = processor.next_task()
docs = StudyInfo().do_task(task, study.id, workflow_model.id, "documents")
self.assertTrue(isinstance(docs, Box))
self.assertTrue(isinstance(docs, Box))
docs = StudyInfo().do_task_validate_only(task, study.id, workflow_model.id, "documents")
self.assertTrue(isinstance(docs, Box))