Beispiel #1
0
    def test_get_documents_has_file_details(self, mock_docs):

        # mock out the protocol builder
        docs_response = self.protocol_builder_response('required_docs.json')
        mock_docs.return_value = json.loads(docs_response)

        user = self.create_user_with_study_and_workflow()

        # Add a document to the study with the correct code.
        workflow = self.create_workflow('docx')
        irb_code = "UVACompl_PRCAppr"  # The first file referenced in pb required docs.
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'1234',
                                      irb_doc_code=irb_code)

        docs = StudyService().get_documents_status(workflow.study_id)
        self.assertIsNotNone(docs)
        self.assertEqual("not_started", docs["UVACompl_PRCAppr"]['status'])
        self.assertEqual(1, docs["UVACompl_PRCAppr"]['count'])
        self.assertIsNotNone(docs["UVACompl_PRCAppr"]['files'][0])
        self.assertIsNotNone(docs["UVACompl_PRCAppr"]['files'][0]['file_id'])
        self.assertEqual(workflow.id,
                         docs["UVACompl_PRCAppr"]['files'][0]['workflow_id'])
Beispiel #2
0
    def test_new_approval_requests_after_file_modification_create_new_requests(
            self):
        self.load_example_data()
        self.create_reference_document()
        workflow = self.create_workflow('empty_workflow')
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'5678',
                                      irb_doc_code="AD_CoCAppr")

        ApprovalService.add_approval(study_id=workflow.study_id,
                                     workflow_id=workflow.id,
                                     approver_uid="dhf8r")

        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'5678',
                                      irb_doc_code="UVACompl_PRCAppr")

        ApprovalService.add_approval(study_id=workflow.study_id,
                                     workflow_id=workflow.id,
                                     approver_uid="dhf8r")
        self.assertEqual(2, db.session.query(ApprovalModel).count())
        models = db.session.query(ApprovalModel).order_by(
            ApprovalModel.version).all()
        self.assertEqual(1, models[0].version)
        self.assertEqual(2, models[1].version)
Beispiel #3
0
    def test_delete_irb_document(self):
        self.load_example_data()
        irb_code = 'Study_Protocol_Document'

        workflow = self.create_workflow('add_delete_irb_document')
        study_id = workflow.study_id

        workflow_api = self.get_workflow_api(workflow)
        first_task = workflow_api.next_task

        # Should not have any files yet
        files = FileService.get_files_for_study(study_id)
        self.assertEqual(0, len(files))
        self.assertEqual(False, IsFileUploaded.do_task(
            IsFileUploaded, first_task, study_id, workflow.id, irb_code))

        # Add a file
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="filename.txt", content_type="text",
                                      binary_data=b'1234', irb_doc_code=irb_code)
        # Assert we have the file
        self.assertEqual(True, IsFileUploaded.do_task(
            IsFileUploaded, first_task, study_id, workflow.id, irb_code))

        # run the workflow, which deletes the file
        self.complete_form(workflow, first_task, {'irb_document': irb_code})
        workflow_api = self.get_workflow_api(workflow)
        second_task = workflow_api.next_task
        # make sure it is deleted
        self.assertEqual(False, IsFileUploaded.do_task(
            IsFileUploaded, second_task, study_id, workflow.id, irb_code))

        print('test_delete_irb_document')
Beispiel #4
0
    def test_add_file_from_task_increments_version_and_replaces_on_subsequent_add(
            self):
        self.load_example_data()
        self.create_reference_document()
        workflow = self.create_workflow('file_upload_form')
        processor = WorkflowProcessor(workflow)
        task = processor.next_task()
        irb_code = "UVACompl_PRCAppr"  # The first file referenced in pb required docs.
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'1234',
                                      irb_doc_code=irb_code)
        # Add the file again with different data
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'5678',
                                      irb_doc_code=irb_code)

        file_models = FileService.get_workflow_files(workflow_id=workflow.id)
        self.assertEqual(1, len(file_models))

        file_data = FileService.get_workflow_data_files(
            workflow_id=workflow.id)
        self.assertEqual(1, len(file_data))
        self.assertEqual(2, file_data[0].version)
Beispiel #5
0
    def test_get_study_has_details_about_files(self):

        # Set up the study and attach a file to it.
        self.load_example_data()
        self.create_reference_document()
        workflow = self.create_workflow('file_upload_form')
        processor = WorkflowProcessor(workflow)
        task = processor.next_task()
        irb_code = "UVACompl_PRCAppr"  # The first file referenced in pb required docs.
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anything.png",
                                      content_type="png",
                                      binary_data=b'1234',
                                      irb_doc_code=irb_code)

        api_response = self.app.get('/v1.0/study/%i' % workflow.study_id,
                                    headers=self.logged_in_headers(),
                                    content_type="application/json")
        self.assert_success(api_response)
        study = StudySchema().loads(api_response.get_data(as_text=True))
        self.assertEqual(1, len(study.files))
        self.assertEqual("UVA Compliance/PRC Approval",
                         study.files[0]["category"])
        self.assertEqual("Cancer Center's PRC Approval Form",
                         study.files[0]["description"])
        self.assertEqual("UVA Compliance/PRC Approval.png",
                         study.files[0]["download_name"])
    def test_get_zipped_files(self):
        self.load_example_data()

        workflow = self.create_workflow('get_zip_file')
        study_id = workflow.study_id
        workflow_api = self.get_workflow_api(workflow)
        task = workflow_api.next_task

        # Add files to use in the test
        model_1 = FileService.add_workflow_file(
            workflow_id=workflow.id,
            name="document_1.png",
            content_type="text",
            task_spec_name=task.name,
            binary_data=b'1234',
            irb_doc_code='Study_Protocol_Document')
        model_2 = FileService.add_workflow_file(workflow_id=workflow.id,
                                                name="document_2.txt",
                                                content_type="text",
                                                task_spec_name=task.name,
                                                binary_data=b'1234',
                                                irb_doc_code='Study_App_Doc')
        model_3 = FileService.add_workflow_file(
            workflow_id=workflow.id,
            name="document_3.pdf",
            content_type="text",
            task_spec_name=task.name,
            binary_data=b'1234',
            irb_doc_code='AD_Consent_Model')

        file_ids = [{
            'file_id': model_1.id
        }, {
            'file_id': model_2.id
        }, {
            'file_id': model_3.id
        }]
        workflow_api = self.complete_form(workflow, task,
                                          {'file_ids': file_ids})
        next_task = workflow_api.next_task
        file_model_id = next_task.data['zip_file']['id']

        file_data = session.query(FileDataModel).filter(
            FileDataModel.file_model_id == file_model_id).first()

        # Test what we get back in the zipped file
        with zipfile.ZipFile(io.BytesIO(file_data.data), 'r') as zf:
            self.assertIsInstance(zf, zipfile.ZipFile)
            for name in zf.namelist():
                info = zf.getinfo(name)
                self.assertIn(os.path.basename(info.filename), [
                    f'{study_id} Protocol document_1.png',
                    f'{study_id} Application document_2.txt',
                    f'{study_id} Model document_3.pdf'
                ])
                file = zf.read(name)
                self.assertEqual(b'1234', file)
Beispiel #7
0
 def do_task(self, task, study_id, workflow_id, *args, **kwargs):
     workflow = session.query(WorkflowModel).filter(
         WorkflowModel.id == workflow_id).first()
     final_document_stream = self.process_template(task, study_id, workflow,
                                                   *args, **kwargs)
     file_name = args[0]
     irb_doc_code = args[1]
     FileService.add_workflow_file(workflow_id=workflow_id,
                                   name=file_name,
                                   content_type=CONTENT_TYPES['docx'],
                                   binary_data=final_document_stream.read(),
                                   irb_doc_code=irb_doc_code)
Beispiel #8
0
 def test_do_task_with_blank_second_approver(self):
     self.load_example_data()
     self.create_reference_document()
     workflow = self.create_workflow('empty_workflow')
     processor = WorkflowProcessor(workflow)
     task = processor.next_task()
     task.data = {"study": {"approval1": "dhf8r", 'approval2':''}}
     FileService.add_workflow_file(workflow_id=workflow.id,
                                   irb_doc_code="UVACompl_PRCAppr",
                                   name="anything.png", content_type="text",
                                   binary_data=b'1234')
     script = RequestApproval()
     script.do_task(task, workflow.study_id, workflow.id, "study.approval1", "study.approval2")
     self.assertEqual(1, db.session.query(ApprovalModel).count())
Beispiel #9
0
    def test_workflow_restart_delete_files(self):
        self.load_example_data()
        irb_code = 'Study_Protocol_Document'

        workflow = self.create_workflow('add_delete_irb_document')
        study_id = workflow.study_id

        workflow_api = self.get_workflow_api(workflow)
        first_task = workflow_api.next_task

        # Should not have any files yet
        files = FileService.get_files_for_study(study_id)
        self.assertEqual(0, len(files))
        self.assertEqual(
            False,
            IsFileUploaded.do_task(IsFileUploaded, first_task, study_id,
                                   workflow.id, irb_code))

        # Add a file
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="filename.txt",
                                      content_type="text",
                                      binary_data=b'1234',
                                      irb_doc_code=irb_code)
        # Assert we have the file
        self.assertEqual(
            True,
            IsFileUploaded.do_task(IsFileUploaded, first_task, study_id,
                                   workflow.id, irb_code))

        workflow_api = self.restart_workflow_api(workflow_api,
                                                 delete_files=False)
        first_task = workflow_api.next_task

        # Assert we still have the file
        self.assertEqual(
            True,
            IsFileUploaded.do_task(IsFileUploaded, first_task, study_id,
                                   workflow.id, irb_code))

        workflow_api = self.restart_workflow_api(workflow_api,
                                                 delete_files=True)
        first_task = workflow_api.next_task

        # Assert we do not have the file
        self.assertEqual(
            False,
            IsFileUploaded.do_task(IsFileUploaded, first_task, study_id,
                                   workflow.id, irb_code))
Beispiel #10
0
def add_file(workflow_id=None, task_spec_name=None, form_field_key=None):
    file = connexion.request.files['file']
    if workflow_id:
        if form_field_key is None:
            raise ApiError(
                'invalid_workflow_file',
                'When adding a workflow related file, you must specify a form_field_key'
            )
        if task_spec_name is None:
            raise ApiError(
                'invalid_workflow_file',
                'When adding a workflow related file, you must specify a task_spec_name'
            )
        file_model = FileService.add_workflow_file(
            workflow_id=workflow_id,
            irb_doc_code=form_field_key,
            task_spec_name=task_spec_name,
            name=file.filename,
            content_type=file.content_type,
            binary_data=file.stream.read())
    else:
        raise ApiError(
            "invalid_file",
            "You must supply either a workflow spec id or a workflow_id and form_field_key."
        )

    return FileSchema().dump(to_file_api(file_model))
 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)
 def test_file_data_set_invalid_irb_code_fails(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='Activity01',
                                          name="anything.png",
                                          content_type="text",
                                          binary_data=b'1234',
                                          irb_doc_code=irb_code)
     processor = WorkflowProcessor(workflow_model)
     task = processor.next_task()
     with self.assertRaises(ApiError):
         FileDataSet().do_task(task,
                               study.id,
                               workflow_model.id,
                               key="irb_code",
                               value="My_Pretty_Pony",
                               file_id=file.id)
Beispiel #13
0
    def test_get_not_really_csv_content(self):
        self.load_example_data()
        self.create_reference_document()
        workflow = self.create_workflow('empty_workflow')
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'5678',
                                      irb_doc_code="AD_CoCAppr")

        ApprovalService.add_approval(study_id=workflow.study_id,
                                     workflow_id=workflow.id,
                                     approver_uid="dhf8r")
        records = ApprovalService.get_not_really_csv_content()

        self.assertEqual(len(records), 2)
Beispiel #14
0
    def test_create_approval_record(self):
        self.create_reference_document()
        workflow = self.create_workflow("empty_workflow")
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'5678',
                                      irb_doc_code="UVACompl_PRCAppr")

        ApprovalService.add_approval(study_id=workflow.study_id,
                                     workflow_id=workflow.id,
                                     approver_uid="dhf8r")
        self.assertEqual(1, db.session.query(ApprovalModel).count())
        model = db.session.query(ApprovalModel).first()
        self.assertEqual(workflow.study_id, model.study_id)
        self.assertEqual(workflow.id, model.workflow_id)
        self.assertEqual("dhf8r", model.approver_uid)
        self.assertEqual(1, model.version)
Beispiel #15
0
 def test_add_file_from_form_increments_version_and_replaces_on_subsequent_add_with_same_name(
         self):
     self.load_example_data()
     self.create_reference_document()
     workflow = self.create_workflow('file_upload_form')
     processor = WorkflowProcessor(workflow)
     task = processor.next_task()
     irb_code = "UVACompl_PRCAppr"  # The first file referenced in pb required docs.
     FileService.add_workflow_file(workflow_id=workflow.id,
                                   irb_doc_code=irb_code,
                                   name="anything.png",
                                   content_type="text",
                                   binary_data=b'1234')
     # Add the file again with different data
     FileService.add_workflow_file(workflow_id=workflow.id,
                                   irb_doc_code=irb_code,
                                   name="anything.png",
                                   content_type="text",
                                   binary_data=b'5678')
Beispiel #16
0
    def test_directory_list(self):
        self.load_example_data()
        irb_code_1 = 'UVACompl_PRCAppr'
        irb_code_2 = 'Study_App_Doc'

        workflow = self.create_workflow('empty_workflow')
        first_task = self.get_workflow_api(workflow).next_task
        study_id = workflow.study_id

        # Add a file
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="something.png",
                                      content_type="text",
                                      binary_data=b'1234',
                                      irb_doc_code=irb_code_1)
        # Add second file
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'5678',
                                      irb_doc_code=irb_code_2)

        # Get back the list of documents and their directories.
        rv = self.app.get('/v1.0/document_directory/%i' % study_id,
                          headers=self.logged_in_headers())
        self.assert_success(rv)
        json_data = json.loads(rv.get_data(as_text=True))
        print(json_data)
        self.assertEqual(2, len(json_data))
        self.assertEqual('UVA Compliance', json_data[0]['level'])
        self.assertEqual('PRC Approval', json_data[0]['children'][0]['level'])
        self.assertEqual(
            'something.png',
            json_data[0]['children'][0]['children'][0]['file']['name'])
        self.assertEqual('Study', json_data[1]['level'])
        self.assertEqual('Application', json_data[1]['children'][0]['level'])
        self.assertEqual('Document',
                         json_data[1]['children'][0]['children'][0]['level'])
        self.assertEqual(
            'anything.png', json_data[1]['children'][0]['children'][0]
            ['children'][0]['file']['name'])
Beispiel #17
0
    def test_delete_file_after_approval(self):
        self.create_reference_document()
        workflow = self.create_workflow("empty_workflow")
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'5678',
                                      irb_doc_code="UVACompl_PRCAppr")
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anotother_anything.png",
                                      content_type="text",
                                      binary_data=b'1234',
                                      irb_doc_code="Study_App_Doc")

        ApprovalService.add_approval(study_id=workflow.study_id,
                                     workflow_id=workflow.id,
                                     approver_uid="dhf8r")

        file = session.query(FileModel).\
            filter(FileModel.workflow_id == workflow.id).\
            filter(FileModel.name == "anything.png").first()
        self.assertFalse(file.archived)
        rv = self.app.get('/v1.0/file/%i' % file.id,
                          headers=self.logged_in_headers())
        self.assert_success(rv)

        rv = self.app.delete('/v1.0/file/%i' % file.id,
                             headers=self.logged_in_headers())
        self.assert_success(rv)

        session.refresh(file)
        self.assertTrue(file.archived)

        ApprovalService.add_approval(study_id=workflow.study_id,
                                     workflow_id=workflow.id,
                                     approver_uid="dhf8r")

        approvals = session.query(ApprovalModel)\
            .filter(ApprovalModel.status == ApprovalStatus.PENDING.value)\
            .filter(ApprovalModel.study_id == workflow.study_id).all()

        self.assertEqual(1, len(approvals))
        self.assertEqual(1, len(approvals[0].approval_files))
Beispiel #18
0
    def test_file_datastore_workflow(self):
        self.load_example_data()
        # we need to create a file with an IRB code
        # for this study
        workflow = self.create_workflow('file_data_store')
        irb_code = "UVACompl_PRCAppr"  # The first file referenced in pb required docs.
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name='task1',
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'1234',
                                      irb_doc_code=irb_code)

        processor = WorkflowProcessor(workflow)
        processor.do_engine_steps()
        task_data = processor.bpmn_workflow.last_task.data
        self.assertTrue(str(task_data['fileid']) in task_data['fileurl'])
        self.assertEqual(task_data['filename'], 'anything.png')
        self.assertEqual(task_data['output'], 'me')
        self.assertEqual(task_data['output2'], 'nope')
Beispiel #19
0
    def test_replace_archive_file_unarchives_the_file_and_updates(self):
        self.load_example_data()
        workflow = self.create_workflow('file_upload_form')
        processor = WorkflowProcessor(workflow)
        task = processor.next_task()
        irb_code = "UVACompl_PRCAppr"  # The first file referenced in pb required docs.
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      irb_doc_code=irb_code,
                                      task_spec_name=task.get_name(),
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'1234')

        # Archive the file
        file_models = FileService.get_workflow_files(workflow_id=workflow.id)
        self.assertEqual(1, len(file_models))
        file_model = file_models[0]
        file_model.archived = True
        db.session.add(file_model)

        # Assure that the file no longer comes back.
        file_models = FileService.get_workflow_files(workflow_id=workflow.id)
        self.assertEqual(0, len(file_models))

        # Add the file again with different data
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      irb_doc_code=irb_code,
                                      task_spec_name=task.get_name(),
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'5678')

        file_models = FileService.get_workflow_files(workflow_id=workflow.id)
        self.assertEqual(1, len(file_models))

        file_data = FileService.get_workflow_data_files(
            workflow_id=workflow.id)

        self.assertEqual(1, len(file_data))
        self.assertEqual(2, file_data[0].version)
        self.assertEqual(b'5678', file_data[0].data)
Beispiel #20
0
    def test_delete_irb_document_list(self):
        # try deleting a list of files
        self.load_example_data()
        irb_code_1 = 'Study_Protocol_Document'
        irb_code_2 = 'Study_App_Doc'
        irb_codes = [irb_code_1, irb_code_2]

        workflow = self.create_workflow('add_delete_irb_document')
        study_id = workflow.study_id

        workflow_api = self.get_workflow_api(workflow)
        first_task = workflow_api.next_task

        # Should not have any files yet
        files = FileService.get_files_for_study(study_id)
        self.assertEqual(0, len(files))
        self.assertEqual(False, IsFileUploaded.do_task(IsFileUploaded, first_task, study_id, workflow.id, irb_code_1))
        self.assertEqual(False, IsFileUploaded.do_task(IsFileUploaded, first_task, study_id, workflow.id, irb_code_2))

        # Add a file
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="filename.txt", content_type="text",
                                      binary_data=b'1234', irb_doc_code=irb_code_1)
        # Add another file
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="filename.txt", content_type="text",
                                      binary_data=b'1234', irb_doc_code=irb_code_2)
        self.assertEqual(True, IsFileUploaded.do_task(
            IsFileUploaded, first_task, study_id, workflow.id, irb_code_1))
        self.assertEqual(True, IsFileUploaded.do_task(
            IsFileUploaded, first_task, study_id, workflow.id, irb_code_2))

        self.complete_form(workflow, first_task, {'irb_document': irb_codes})
        workflow_api = self.get_workflow_api(workflow)
        second_task = workflow_api.next_task
        self.assertEqual(False, IsFileUploaded.do_task(
            IsFileUploaded, second_task, study_id, workflow.id, irb_code_1))
        self.assertEqual(False, IsFileUploaded.do_task(
            IsFileUploaded, second_task, study_id, workflow.id, irb_code_2))
Beispiel #21
0
 def test_add_file_from_form_allows_multiple_files_with_different_names(
         self):
     self.load_example_data()
     self.create_reference_document()
     workflow = self.create_workflow('file_upload_form')
     processor = WorkflowProcessor(workflow)
     task = processor.next_task()
     irb_code = "UVACompl_PRCAppr"  # The first file referenced in pb required docs.
     FileService.add_workflow_file(workflow_id=workflow.id,
                                   irb_doc_code=irb_code,
                                   name="anything.png",
                                   content_type="text",
                                   binary_data=b'1234')
     # Add the file again with different data
     FileService.add_workflow_file(workflow_id=workflow.id,
                                   irb_doc_code=irb_code,
                                   name="a_different_thing.png",
                                   content_type="text",
                                   binary_data=b'5678')
     file_models = FileService.get_workflow_files(workflow_id=workflow.id)
     self.assertEqual(2, len(file_models))
Beispiel #22
0
    def test_get_all_studies(self):
        user = self.create_user_with_study_and_workflow()
        study = db.session.query(StudyModel).filter_by(
            user_uid=user.uid).first()
        self.assertIsNotNone(study)

        # Add a document to the study with the correct code.
        workflow1 = self.create_workflow('docx', study=study)
        workflow2 = self.create_workflow('empty_workflow', study=study)

        # Add files to both workflows.
        FileService.add_workflow_file(workflow_id=workflow1.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'1234',
                                      irb_doc_code="UVACompl_PRCAppr")
        FileService.add_workflow_file(workflow_id=workflow1.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'1234',
                                      irb_doc_code="AD_Consent_Model")
        FileService.add_workflow_file(workflow_id=workflow2.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'1234',
                                      irb_doc_code="UVACompl_PRCAppr")

        studies = StudyService().get_all_studies_with_files()
        self.assertEqual(1, len(studies))
        self.assertEqual(3, len(studies[0].files))
Beispiel #23
0
    def test_new_approval_cancels_all_previous_approvals(self):
        self.create_reference_document()
        workflow = self.create_workflow("empty_workflow")
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'5678',
                                      irb_doc_code="UVACompl_PRCAppr")
        ApprovalService.add_approval(study_id=workflow.study_id,
                                     workflow_id=workflow.id,
                                     approver_uid="dhf8r")
        ApprovalService.add_approval(study_id=workflow.study_id,
                                     workflow_id=workflow.id,
                                     approver_uid="lb3dp")

        current_count = ApprovalModel.query.count()
        self.assertTrue(current_count, 2)

        FileService.add_workflow_file(workflow_id=workflow.id,
                                      name="borderline.png",
                                      content_type="text",
                                      binary_data=b'906090',
                                      irb_doc_code="AD_CoCAppr")

        ApprovalService.add_approval(study_id=workflow.study_id,
                                     workflow_id=workflow.id,
                                     approver_uid="dhf8r")

        current_count = ApprovalModel.query.count()
        canceled_count = ApprovalModel.query.filter(
            ApprovalModel.status == ApprovalStatus.CANCELED.value)
        self.assertTrue(current_count, 2)
        self.assertTrue(current_count, 3)

        ApprovalService.add_approval(study_id=workflow.study_id,
                                     workflow_id=workflow.id,
                                     approver_uid="lb3dp")

        current_count = ApprovalModel.query.count()
        self.assertTrue(current_count, 4)
    def test_delete_workflow(self):
        self.load_example_data()
        workflow = session.query(WorkflowModel).first()
        FileService.add_workflow_file(workflow_id=workflow.id, task_spec_name='TaskSpec01',
                                      name="anything.png", content_type="text",
                                      binary_data=b'5678', irb_doc_code="UVACompl_PRCAppr" )

        workflow_files = session.query(FileModel).filter_by(workflow_id=workflow.id)
        self.assertEqual(workflow_files.count(), 1)
        workflow_files_ids = [file.id for file in workflow_files]

        rv = self.app.delete(f'/v1.0/workflow/{workflow.id}', headers=self.logged_in_headers())
        self.assert_success(rv)

        # No files should have the deleted workflow id anymore
        workflow_files = session.query(FileModel).filter_by(workflow_id=workflow.id)
        self.assertEqual(workflow_files.count(), 0)

        # Finally, let's confirm the file was archived
        workflow_files = session.query(FileModel).filter(FileModel.id.in_(workflow_files_ids))
        for file in workflow_files:
            self.assertTrue(file.archived)
            self.assertIsNone(file.workflow_id)
Beispiel #25
0
    def test_file_uploaded_pass(self):
        self.load_example_data()
        irb_code_1 = 'UVACompl_PRCAppr'
        irb_code_2 = 'Study_App_Doc'

        workflow = self.create_workflow('empty_workflow')
        first_task = self.get_workflow_api(workflow).next_task
        study_id = workflow.study_id

        # We shouldn't have any files yet.
        files = FileService.get_files_for_study(study_id)
        self.assertEqual(0, len(files))
        self.assertEqual(False, IsFileUploaded.do_task(IsFileUploaded, first_task, study_id, workflow.id, irb_code_1))

        # Add a file
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="something.png", content_type="text",
                                      binary_data=b'1234', irb_doc_code=irb_code_1)

        # Make sure we find the file
        files = FileService.get_files_for_study(study_id)
        self.assertEqual(1, len(files))
        self.assertEqual(True, IsFileUploaded.do_task(IsFileUploaded, first_task, study_id, workflow.id, irb_code_1))

        # Add second file
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="anything.png", content_type="text",
                                      binary_data=b'5678', irb_doc_code=irb_code_2)

        # Make sure we find both files.
        files = FileService.get_files_for_study(study_id)
        self.assertEqual(2, len(files))
        self.assertEqual(True, IsFileUploaded.do_task(IsFileUploaded, first_task, study_id, workflow.id, irb_code_1))
        self.assertEqual(True, IsFileUploaded.do_task(IsFileUploaded, first_task, study_id, workflow.id, irb_code_2))
Beispiel #26
0
    def test_publish_to_github_updates(self, mock_github):
        mock_github.return_value = FakeGithub()

        self.load_example_data()
        workflow = self.create_workflow('file_upload_form')
        processor = WorkflowProcessor(workflow)
        task = processor.next_task()
        irb_code = "UVACompl_PRCAppr"  # The first file referenced in pb required docs.
        file_model = FileService.add_workflow_file(
            workflow_id=workflow.id,
            irb_doc_code=irb_code,
            task_spec_name=task.get_name(),
            name="anything.png",
            content_type="text",
            binary_data=b'1234')
        result = FileService.publish_to_github([file_model.id])

        self.assertEqual(result['updated'], True)
    def test_email_script_attachments(self):
        self.load_example_data()
        irb_code_1 = 'Study_App_Doc'
        irb_code_2 = 'Study_Protocol_Document'

        workflow = self.create_workflow('email_script')
        workflow_api = self.get_workflow_api(workflow)
        first_task = workflow_api.next_task

        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="something.png",
                                      content_type="text",
                                      binary_data=b'1234',
                                      irb_doc_code=irb_code_1)
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="another.png",
                                      content_type="text",
                                      binary_data=b'67890',
                                      irb_doc_code=irb_code_1)
        FileService.add_workflow_file(workflow_id=workflow.id,
                                      task_spec_name=first_task.name,
                                      name="anything.png",
                                      content_type="text",
                                      binary_data=b'5678',
                                      irb_doc_code=irb_code_2)

        with mail.record_messages() as outbox:
            self.complete_form(
                workflow, first_task, {
                    'subject':
                    'My Test Subject',
                    'recipients':
                    '*****@*****.**',
                    'doc_codes': [{
                        'doc_code': irb_code_1
                    }, {
                        'doc_code': irb_code_2
                    }]
                })
            self.assertEqual(1, len(outbox))
            self.assertEqual(3, len(outbox[0].attachments))
            self.assertEqual('image/png',
                             outbox[0].attachments[0].content_type)
            self.assertEqual('something.png',
                             outbox[0].attachments[0].filename)
            self.assertEqual(b'1234', outbox[0].attachments[0].data)
Beispiel #28
0
    def test_update_from_github(self, mock_github):
        mock_github.return_value = FakeGithub()

        self.load_example_data()
        workflow = self.create_workflow('file_upload_form')
        processor = WorkflowProcessor(workflow)
        task = processor.next_task()
        irb_code = "UVACompl_PRCAppr"  # The first file referenced in pb required docs.
        file_model = FileService.add_workflow_file(
            workflow_id=workflow.id,
            irb_doc_code=irb_code,
            task_spec_name=task.get_name(),
            name="anything.png",
            content_type="text",
            binary_data=b'1234')
        FileService.update_from_github([file_model.id])

        file_model_data = FileDataModel.query.filter_by(
            file_model_id=file_model.id).order_by(desc(
                FileDataModel.version)).first()
        self.assertEqual(file_model_data.data, b'Some bytes')