def test_info_script_documents(self, mock_get):
        app.config['PB_ENABLED'] = True
        mock_get.return_value.ok = True
        mock_get.return_value.text = self.protocol_builder_response(
            'required_docs.json')
        response = ProtocolBuilderService.get_required_docs(self.test_study_id)
        study_info, second_task = self.do_work(info_type='documents')
        self.assertEqual(study_info, second_task.data['info'])
        self.assertEqual(0, len(study_info['Grant_App']['files']),
                         "Grant_App has not files yet.")
        # Add a grant app file
        data = {'file': (io.BytesIO(b"abcdef"), 'random_fact.svg')}
        rv = self.app.post(
            '/v1.0/file?study_id=%i&workflow_id=%s&task_spec_name=%s&form_field_key=%s'
            % (self.workflow.study_id, self.workflow.id, second_task.name,
               'Grant_App'),
            data=data,
            follow_redirects=True,
            content_type='multipart/form-data',
            headers=self.logged_in_headers())
        self.assert_success(rv)
        file_data = json.loads(rv.get_data(as_text=True))

        # Now get the study info again.
        study_info = StudyInfo().do_task(self.workflow_api.study_id,
                                         self.workflow.study.id,
                                         self.workflow.id, 'documents')
        # The data should contain a file.
        self.assertEqual(1, len(study_info['Grant_App']['files']),
                         "Grant_App has exactly one file.")

        # This file data returned should be the same as what we get back about the file when we uploaded it,
        # but the details on the document should be removed, because that would be recursive.
        del file_data['document']
        self.assertEqual(file_data, study_info['Grant_App']['files'][0])
Beispiel #2
0
    def test_validate_returns_error_if_reference_files_do_not_exist(
            self, mock_get):
        mock_get.return_value.ok = True
        mock_get.return_value.text = self.protocol_builder_response(
            'required_docs.json')

        self.load_example_data()
        self.create_reference_document()
        study = session.query(StudyModel).first()
        workflow_spec_model = self.load_test_spec("two_forms")
        workflow_model = StudyService._create_workflow_model(
            study, workflow_spec_model)
        processor = WorkflowProcessor(workflow_model)
        task = processor.next_task()

        # Remove the reference file.
        file_model = db.session.query(FileModel). \
            filter(FileModel.is_reference == True). \
            filter(FileModel.name == FileService.DOCUMENT_LIST).first()
        if file_model:
            db.session.query(FileDataModel).filter(
                FileDataModel.file_model_id == file_model.id).delete()
            db.session.query(FileModel).filter(
                FileModel.id == file_model.id).delete()
        db.session.commit()
        db.session.flush()

        with self.assertRaises(ApiError):
            StudyInfo().do_task_validate_only(task, study.id, "documents")
Beispiel #3
0
 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))
Beispiel #4
0
 def test_study_info_returns_a_box_object_for_all_validations(
         self, mock_get):
     app.config['PB_ENABLED'] = True
     mock_get.return_value.ok = True
     for option in StudyInfo.type_options:
         if option == 'info':
             mock_get.return_value.text = self.protocol_builder_response(
                 'irb_info.json')
         elif option == 'investigators':
             mock_get.return_value.text = self.protocol_builder_response(
                 'investigators.json')
         elif option == 'roles':
             mock_get.return_value.text = self.protocol_builder_response(
                 'investigators.json')
         elif option == 'details':
             mock_get.return_value.text = self.protocol_builder_response(
                 'study_details.json')
         elif option == 'documents':
             mock_get.return_value.text = self.protocol_builder_response(
                 'required_docs.json')
         elif option == 'sponsors':
             mock_get.return_value.text = self.protocol_builder_response(
                 'sponsors.json')
         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_file_data_set_changes_irb_code(self, mock_get):
     mock_get.return_value.ok = True
     mock_get.return_value.text = self.protocol_builder_response(
         'required_docs.json')
     self.load_example_data()
     study = session.query(StudyModel).first()
     workflow_spec_model = self.load_test_spec("two_forms")
     workflow_model = StudyService._create_workflow_model(
         study, workflow_spec_model)
     irb_code = "UVACompl_PRCAppr"  # The first file referenced in pb required docs.
     file = FileService.add_workflow_file(workflow_id=workflow_model.id,
                                          task_spec_name='TaskSpec01',
                                          name="anything.png",
                                          content_type="text",
                                          binary_data=b'1234',
                                          irb_doc_code=irb_code)
     processor = WorkflowProcessor(workflow_model)
     task = processor.next_task()
     FileDataSet().do_task(task,
                           study.id,
                           workflow_model.id,
                           key="irb_code",
                           value="Study_App_Doc",
                           file_id=file.id)
     docs = StudyInfo().do_task(task, study.id, workflow_model.id,
                                "documents")
     self.assertTrue(isinstance(docs, Box))
     self.assertEqual(1, len(docs.Study_App_Doc.files))
     self.assertEqual("Study_App_Doc",
                      docs.Study_App_Doc.files[0].data_store.irb_code)
Beispiel #6
0
 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)
 def test_study_info_returns_a_box_object(self, mock_get):
     mock_get.return_value.ok = True
     mock_get.return_value.text = self.protocol_builder_response(
         'required_docs.json')
     self.load_example_data()
     study = session.query(StudyModel).first()
     workflow_spec_model = self.load_test_spec("two_forms")
     workflow_model = StudyService._create_workflow_model(
         study, workflow_spec_model)
     processor = WorkflowProcessor(workflow_model)
     task = processor.next_task()
     docs = StudyInfo().do_task(task, study.id, workflow_model.id,
                                "documents")
     self.assertTrue(isinstance(docs, Box))
     docs = StudyInfo().do_task_validate_only(task, study.id,
                                              workflow_model.id,
                                              "documents")
     self.assertTrue(isinstance(docs, Box))
    def test_no_validation_error_when_correct_file_exists(self, mock_get):
        mock_get.return_value.ok = True
        mock_get.return_value.text = self.protocol_builder_response(
            'required_docs.json')

        self.load_example_data()
        study = session.query(StudyModel).first()
        workflow_spec_model = self.load_test_spec("two_forms")
        workflow_model = StudyService._create_workflow_model(
            study, workflow_spec_model)
        processor = WorkflowProcessor(workflow_model)
        task = processor.next_task()
        StudyInfo().do_task_validate_only(task, study.id, workflow_model.id,
                                          "documents")
    def do_work(self, info_type):
        app.config['PB_ENABLED'] = True
        self.load_example_data()
        self.workflow = self.create_workflow('study_info_script')
        self.workflow_api = self.get_workflow_api(self.workflow)
        # grab study_info directly from script
        study_info = StudyInfo().do_task(self.workflow_api.study_id,
                                         self.workflow.study.id,
                                         self.workflow.id, info_type)

        # grab study info through a workflow
        first_task = self.workflow_api.next_task
        self.complete_form(self.workflow, first_task, {'which': info_type})
        workflow_api = self.get_workflow_api(self.workflow)
        second_task = workflow_api.next_task

        return study_info, second_task
Beispiel #10
0
 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))
Beispiel #11
0
 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))