2020-05-23 19:08:17 +00:00
|
|
|
from tests.base_test import BaseTest
|
|
|
|
|
2020-05-24 20:13:15 +00:00
|
|
|
from crc.scripts.request_approval import RequestApproval
|
2020-05-23 19:08:17 +00:00
|
|
|
from crc.services.workflow_processor import WorkflowProcessor
|
2020-05-24 20:13:15 +00:00
|
|
|
from crc.api.common import ApiError
|
2020-05-23 19:08:17 +00:00
|
|
|
|
|
|
|
from crc import db
|
|
|
|
from crc.models.approval import ApprovalModel
|
|
|
|
|
|
|
|
|
|
|
|
class TestRequestApprovalScript(BaseTest):
|
|
|
|
|
2020-05-24 20:13:15 +00:00
|
|
|
def test_do_task(self):
|
2020-05-23 19:08:17 +00:00
|
|
|
self.load_example_data()
|
|
|
|
self.create_reference_document()
|
|
|
|
workflow = self.create_workflow('empty_workflow')
|
|
|
|
processor = WorkflowProcessor(workflow)
|
|
|
|
task = processor.next_task()
|
2020-05-25 19:30:06 +00:00
|
|
|
task.data = {"study": {"approvals": ['dhf8r', 'lb3dp']}}
|
2020-05-23 19:08:17 +00:00
|
|
|
|
|
|
|
script = RequestApproval()
|
2020-05-25 19:30:06 +00:00
|
|
|
script.do_task(task, workflow.study_id, workflow.id, "study.approvals")
|
2020-05-23 19:08:17 +00:00
|
|
|
self.assertEquals(2, db.session.query(ApprovalModel).count())
|
|
|
|
|
2020-05-24 20:13:15 +00:00
|
|
|
def test_do_task_with_incorrect_argument(self):
|
|
|
|
"""This script should raise an error if it can't figure out the approvers."""
|
2020-05-23 19:08:17 +00:00
|
|
|
self.load_example_data()
|
|
|
|
self.create_reference_document()
|
|
|
|
workflow = self.create_workflow('empty_workflow')
|
|
|
|
processor = WorkflowProcessor(workflow)
|
|
|
|
task = processor.next_task()
|
2020-05-24 20:13:15 +00:00
|
|
|
task.data = {"approvals": {'dhf8r':"invalid", 'lb3dp':"invalid"}}
|
2020-05-23 19:08:17 +00:00
|
|
|
script = RequestApproval()
|
2020-05-24 20:13:15 +00:00
|
|
|
with self.assertRaises(ApiError):
|
|
|
|
script.do_task(task, workflow.study_id, workflow.id, "approvals")
|
2020-05-23 19:08:17 +00:00
|
|
|
|
2020-05-24 20:13:15 +00:00
|
|
|
def test_do_task_validate_only(self):
|
|
|
|
self.load_example_data()
|
|
|
|
self.create_reference_document()
|
|
|
|
workflow = self.create_workflow('empty_workflow')
|
|
|
|
processor = WorkflowProcessor(workflow)
|
|
|
|
task = processor.next_task()
|
|
|
|
task.data = {"approvals": ['dhf8r', 'lb3dp']}
|
2020-05-23 19:08:17 +00:00
|
|
|
|
2020-05-24 20:13:15 +00:00
|
|
|
script = RequestApproval()
|
|
|
|
script.do_task_validate_only(task, workflow.study_id, workflow.id, "approvals")
|
|
|
|
self.assertEquals(0, db.session.query(ApprovalModel).count())
|
2020-05-23 19:08:17 +00:00
|
|
|
|