2021-06-15 12:37:42 +00:00
|
|
|
from tests.base_test import BaseTest
|
|
|
|
from crc.scripts.reset_workflow import ResetWorkflow
|
2021-06-15 14:30:18 +00:00
|
|
|
from crc.api.common import ApiError
|
2021-06-15 12:37:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestWorkflowReset(BaseTest):
|
|
|
|
|
2021-06-15 15:15:31 +00:00
|
|
|
def test_workflow_reset_validation(self):
|
|
|
|
self.load_example_data()
|
|
|
|
spec_model = self.load_test_spec('reset_workflow')
|
|
|
|
rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers())
|
|
|
|
self.assertEqual([], rv.json)
|
|
|
|
|
2021-06-15 12:37:42 +00:00
|
|
|
def test_workflow_reset(self):
|
2021-06-15 15:15:31 +00:00
|
|
|
workflow = self.create_workflow('two_user_tasks')
|
2021-06-15 12:37:42 +00:00
|
|
|
workflow_api = self.get_workflow_api(workflow)
|
|
|
|
first_task = workflow_api.next_task
|
|
|
|
self.assertEqual('Task_GetName', first_task.name)
|
|
|
|
|
|
|
|
self.complete_form(workflow, first_task, {'name': 'Mona'})
|
|
|
|
workflow_api = self.get_workflow_api(workflow)
|
|
|
|
second_task = workflow_api.next_task
|
|
|
|
self.assertEqual('Task_GetAge', second_task.name)
|
|
|
|
|
2021-10-05 18:20:03 +00:00
|
|
|
ResetWorkflow().do_task(second_task, workflow.study_id, workflow.id, reset_id='two_user_tasks')
|
2021-06-15 12:37:42 +00:00
|
|
|
|
|
|
|
workflow_api = self.get_workflow_api(workflow)
|
|
|
|
task = workflow_api.next_task
|
|
|
|
self.assertEqual('Task_GetName', task.name)
|
2021-06-15 14:30:18 +00:00
|
|
|
|
|
|
|
def test_workflow_reset_missing_name(self):
|
2021-06-15 15:15:31 +00:00
|
|
|
workflow = self.create_workflow('two_user_tasks')
|
2021-06-15 14:30:18 +00:00
|
|
|
workflow_api = self.get_workflow_api(workflow)
|
|
|
|
first_task = workflow_api.next_task
|
|
|
|
|
|
|
|
with self.assertRaises(ApiError):
|
|
|
|
ResetWorkflow().do_task(first_task, workflow.study_id, workflow.id)
|
|
|
|
|
|
|
|
def test_workflow_reset_bad_name(self):
|
2021-06-15 15:15:31 +00:00
|
|
|
workflow = self.create_workflow('two_user_tasks')
|
2021-06-15 14:30:18 +00:00
|
|
|
workflow_api = self.get_workflow_api(workflow)
|
|
|
|
first_task = workflow_api.next_task
|
|
|
|
|
|
|
|
with self.assertRaises(ApiError):
|
2021-10-05 18:20:03 +00:00
|
|
|
ResetWorkflow().do_task(first_task, workflow.study_id, workflow.id, reset_id='bad_workflow_name')
|