2020-05-24 20:13:15 +00:00
|
|
|
from tests.base_test import BaseTest
|
|
|
|
from crc import db
|
|
|
|
from crc.models.approval import ApprovalModel
|
2020-07-07 00:52:02 +00:00
|
|
|
from crc.services.approval_service import ApprovalService, ApprovalStatus
|
2020-05-24 20:13:15 +00:00
|
|
|
from crc.services.file_service import FileService
|
|
|
|
from crc.services.workflow_processor import WorkflowProcessor
|
|
|
|
|
|
|
|
|
|
|
|
class TestApprovalsService(BaseTest):
|
|
|
|
|
|
|
|
def test_create_approval_record(self):
|
2020-05-29 00:03:50 +00:00
|
|
|
self.create_reference_document()
|
2020-05-24 20:13:15 +00:00
|
|
|
workflow = self.create_workflow("empty_workflow")
|
2020-05-29 00:03:50 +00:00
|
|
|
FileService.add_workflow_file(workflow_id=workflow.id,
|
|
|
|
name="anything.png", content_type="text",
|
|
|
|
binary_data=b'5678', irb_doc_code="UVACompl_PRCAppr" )
|
|
|
|
|
2020-06-05 02:37:28 +00:00
|
|
|
|
2020-05-24 20:13:15 +00:00
|
|
|
ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r")
|
2020-06-05 18:08:46 +00:00
|
|
|
self.assertEqual(1, db.session.query(ApprovalModel).count())
|
2020-05-24 20:13:15 +00:00
|
|
|
model = db.session.query(ApprovalModel).first()
|
2020-06-05 18:08:46 +00:00
|
|
|
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)
|
2020-05-24 20:13:15 +00:00
|
|
|
|
|
|
|
def test_new_requests_dont_add_if_approval_exists_for_current_workflow(self):
|
2020-05-29 00:03:50 +00:00
|
|
|
self.create_reference_document()
|
2020-05-24 20:13:15 +00:00
|
|
|
workflow = self.create_workflow("empty_workflow")
|
2020-05-29 00:03:50 +00:00
|
|
|
FileService.add_workflow_file(workflow_id=workflow.id,
|
|
|
|
name="anything.png", content_type="text",
|
|
|
|
binary_data=b'5678', irb_doc_code="UVACompl_PRCAppr" )
|
|
|
|
|
2020-05-24 20:13:15 +00:00
|
|
|
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="dhf8r")
|
2020-06-05 18:08:46 +00:00
|
|
|
self.assertEqual(1, db.session.query(ApprovalModel).count())
|
2020-05-24 20:13:15 +00:00
|
|
|
model = db.session.query(ApprovalModel).first()
|
2020-06-05 18:08:46 +00:00
|
|
|
self.assertEqual(1, model.version)
|
2020-05-24 20:13:15 +00:00
|
|
|
|
|
|
|
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')
|
2020-05-29 00:03:50 +00:00
|
|
|
FileService.add_workflow_file(workflow_id=workflow.id,
|
|
|
|
name="anything.png", content_type="text",
|
|
|
|
binary_data=b'5678', irb_doc_code="AD_CoCAppr")
|
2020-05-24 20:13:15 +00:00
|
|
|
|
|
|
|
ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r")
|
|
|
|
|
A major refactor of how we search and store files, as there was a lot of confusing bits in here.
From an API point of view you can do the following (and only the following)
/files?workflow_spec_id=x
* You can find all files associated with a workflow_spec_id, and add a file with a workflow_spec_id
/files?workflow_id=x
* You can find all files associated with a workflow_id, and add a file that is directly associated with the workflow
/files?workflow_id=x&form_field_key=y
* You can find all files associated with a form element on a running workflow, and add a new file.
Note: you can add multiple files to the same form_field_key, IF they have different file names. If the same name, the original file is archived,
and the new file takes its place.
The study endpoints always return a list of the file metadata associated with the study. Removed /studies-files, but there is an
endpoint called
/studies/all - that returns all the studies in the system, and does include their files.
On a deeper level:
The File model no longer contains:
- study_id,
- task_id,
- form_field_key
Instead, if the file is associated with workflow - then that is the one way it is connected to the study, and we use this relationship to find files for a study.
A file is never associated with a task_id, as these change when the workflow is reloaded.
The form_field_key must match the irb_doc_code, so when requesting files for a form field, we just look up the irb_doc_code.
2020-05-28 12:27:26 +00:00
|
|
|
FileService.add_workflow_file(workflow_id=workflow.id,
|
|
|
|
name="anything.png", content_type="text",
|
2020-05-29 00:03:50 +00:00
|
|
|
binary_data=b'5678', irb_doc_code="UVACompl_PRCAppr")
|
2020-05-24 20:13:15 +00:00
|
|
|
|
|
|
|
ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r")
|
2020-06-05 18:08:46 +00:00
|
|
|
self.assertEqual(2, db.session.query(ApprovalModel).count())
|
2020-05-24 20:13:15 +00:00
|
|
|
models = db.session.query(ApprovalModel).order_by(ApprovalModel.version).all()
|
2020-06-05 18:08:46 +00:00
|
|
|
self.assertEqual(1, models[0].version)
|
|
|
|
self.assertEqual(2, models[1].version)
|
2020-05-24 20:13:15 +00:00
|
|
|
|
2020-06-22 20:07:57 +00:00
|
|
|
def test_get_health_attesting_records(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_health_attesting_records()
|
|
|
|
|
|
|
|
self.assertEqual(len(records), 1)
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2020-06-22 20:22:56 +00:00
|
|
|
self.assertEqual(len(records), 2)
|
2020-06-22 20:07:57 +00:00
|
|
|
|
2020-07-07 00:52:02 +00:00
|
|
|
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)
|
|
|
|
|
2020-06-05 02:37:28 +00:00
|
|
|
def test_new_approval_sends_proper_emails(self):
|
|
|
|
self.assertEqual(1, 1)
|
|
|
|
|
|
|
|
def test_new_approval_failed_ldap_lookup(self):
|
|
|
|
# failed lookup should send email to sartographysupport@googlegroups.com + Cheryl
|
|
|
|
self.assertEqual(1, 1)
|
|
|
|
|
|
|
|
def test_approve_approval_sends_proper_emails(self):
|
|
|
|
self.assertEqual(1, 1)
|
2020-05-24 20:13:15 +00:00
|
|
|
|
2020-06-05 02:37:28 +00:00
|
|
|
def test_deny_approval_sends_proper_emails(self):
|
|
|
|
self.assertEqual(1, 1)
|