2020-05-24 20:13:15 +00:00
|
|
|
from tests.base_test import BaseTest
|
|
|
|
from crc import db
|
|
|
|
from crc.models.approval import ApprovalModel
|
|
|
|
from crc.services.approval_service import ApprovalService
|
|
|
|
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-05-24 20:13:15 +00:00
|
|
|
ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r")
|
|
|
|
self.assertEquals(1, db.session.query(ApprovalModel).count())
|
|
|
|
model = db.session.query(ApprovalModel).first()
|
|
|
|
self.assertEquals(workflow.study_id, model.study_id)
|
|
|
|
self.assertEquals(workflow.id, model.workflow_id)
|
|
|
|
self.assertEquals("dhf8r", model.approver_uid)
|
|
|
|
self.assertEquals(1, model.version)
|
|
|
|
|
|
|
|
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")
|
|
|
|
self.assertEquals(1, db.session.query(ApprovalModel).count())
|
|
|
|
model = db.session.query(ApprovalModel).first()
|
|
|
|
self.assertEquals(1, model.version)
|
|
|
|
|
|
|
|
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")
|
|
|
|
self.assertEquals(2, db.session.query(ApprovalModel).count())
|
|
|
|
models = db.session.query(ApprovalModel).order_by(ApprovalModel.version).all()
|
|
|
|
self.assertEquals(1, models[0].version)
|
|
|
|
self.assertEquals(2, models[1].version)
|
|
|
|
|
|
|
|
|