Fixed issue where we were passing in a workflow_api instead of a workflow when completing a form in tests.

This commit is contained in:
mike cullerton 2021-04-26 08:58:09 -04:00
parent c002ef1e76
commit 7cca559747
11 changed files with 52 additions and 59 deletions

View File

@ -72,7 +72,7 @@ class TestStudyCancellations(BaseTest):
workflow, study_id = self.load_workflow() workflow, study_id = self.load_workflow()
workflow_api, first_task = self.get_first_task(workflow) workflow_api, first_task = self.get_first_task(workflow)
self.complete_form(workflow_api, first_task, {}) self.complete_form(workflow, first_task, {})
study_result = self.put_study_on_hold(study_id) study_result = self.put_study_on_hold(study_id)
self.assertEqual('New Title', study_result.title) self.assertEqual('New Title', study_result.title)
@ -82,10 +82,10 @@ class TestStudyCancellations(BaseTest):
workflow, study_id = self.load_workflow() workflow, study_id = self.load_workflow()
workflow_api, first_task = self.get_first_task(workflow) workflow_api, first_task = self.get_first_task(workflow)
self.complete_form(workflow_api, first_task, {}) self.complete_form(workflow, first_task, {})
workflow_api, next_task = self.get_second_task(workflow) workflow_api, next_task = self.get_second_task(workflow)
self.complete_form(workflow_api, next_task, {'how_many': 3}) self.complete_form(workflow, next_task, {'how_many': 3})
study_result = self.put_study_on_hold(study_id) study_result = self.put_study_on_hold(study_id)
self.assertEqual('Second Title', study_result.title) self.assertEqual('Second Title', study_result.title)
@ -95,13 +95,13 @@ class TestStudyCancellations(BaseTest):
workflow, study_id = self.load_workflow() workflow, study_id = self.load_workflow()
workflow_api, first_task = self.get_first_task(workflow) workflow_api, first_task = self.get_first_task(workflow)
self.complete_form(workflow_api, first_task, {}) self.complete_form(workflow, first_task, {})
workflow_api, second_task = self.get_second_task(workflow) workflow_api, second_task = self.get_second_task(workflow)
self.complete_form(workflow_api, second_task, {'how_many': 3}) self.complete_form(workflow, second_task, {'how_many': 3})
workflow_api, third_task = self.get_third_task(workflow) workflow_api, third_task = self.get_third_task(workflow)
self.complete_form(workflow_api, third_task, {}) self.complete_form(workflow, third_task, {})
study_result = self.put_study_on_hold(study_id) study_result = self.put_study_on_hold(study_id)
self.assertEqual('Beer consumption in the bipedal software engineer', study_result.title) self.assertEqual('Beer consumption in the bipedal software engineer', study_result.title)

View File

@ -23,7 +23,6 @@ class TestEmailScript(BaseTest):
first_task = self.get_workflow_api(workflow).next_task first_task = self.get_workflow_api(workflow).next_task
workflow = self.get_workflow_api(workflow)
self.complete_form(workflow, first_task, {'subject': 'My Email Subject', 'recipients': 'test@example.com'}) self.complete_form(workflow, first_task, {'subject': 'My Email Subject', 'recipients': 'test@example.com'})
self.assertEqual(1, len(outbox)) self.assertEqual(1, len(outbox))
@ -49,7 +48,6 @@ class TestEmailScript(BaseTest):
def test_bad_email_address_1(self): def test_bad_email_address_1(self):
workflow = self.create_workflow('email_script') workflow = self.create_workflow('email_script')
first_task = self.get_workflow_api(workflow).next_task first_task = self.get_workflow_api(workflow).next_task
workflow = self.get_workflow_api(workflow)
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
self.complete_form(workflow, first_task, {'recipients': 'test@example'}) self.complete_form(workflow, first_task, {'recipients': 'test@example'})
@ -57,7 +55,6 @@ class TestEmailScript(BaseTest):
def test_bad_email_address_2(self): def test_bad_email_address_2(self):
workflow = self.create_workflow('email_script') workflow = self.create_workflow('email_script')
first_task = self.get_workflow_api(workflow).next_task first_task = self.get_workflow_api(workflow).next_task
workflow = self.get_workflow_api(workflow)
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
self.complete_form(workflow, first_task, {'recipients': 'test'}) self.complete_form(workflow, first_task, {'recipients': 'test'})

View File

@ -13,10 +13,10 @@ class TestMessageEvent(BaseTest):
# Start the workflow. # Start the workflow.
first_task = self.get_workflow_api(workflow).next_task first_task = self.get_workflow_api(workflow).next_task
self.assertEqual('Activity_GetData', first_task.name) self.assertEqual('Activity_GetData', first_task.name)
workflow = self.get_workflow_api(workflow)
self.complete_form(workflow, first_task, {'formdata': 'asdf'}) self.complete_form(workflow, first_task, {'formdata': 'asdf'})
workflow = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
self.assertEqual('Activity_HowMany', workflow.next_task.name) self.assertEqual('Activity_HowMany', workflow_api.next_task.name)
# reset the workflow # reset the workflow
# this ultimately calls crc.api.workflow.set_current_task # this ultimately calls crc.api.workflow.set_current_task

View File

@ -67,14 +67,14 @@ class TestMultiinstanceTasksApi(BaseTest):
content_type="application/json") content_type="application/json")
self.assert_success(rv) self.assert_success(rv)
json_data = json.loads(rv.get_data(as_text=True)) json_data = json.loads(rv.get_data(as_text=True))
workflow = WorkflowApiSchema().load(json_data) workflow_api = WorkflowApiSchema().load(json_data)
data = workflow.next_task.data data = workflow_api.next_task.data
data['investigator']['email'] = "dhf8r@virginia.edu" data['investigator']['email'] = "dhf8r@virginia.edu"
self.complete_form(workflow, workflow.next_task, data) self.complete_form(workflow, workflow_api.next_task, data)
#tasks = self.get_workflow_api(workflow).user_tasks #tasks = self.get_workflow_api(workflow).user_tasks
workflow = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
self.assertEqual(WorkflowStatus.complete, workflow.status) self.assertEqual(WorkflowStatus.complete, workflow_api.status)
@patch('crc.services.protocol_builder.requests.get') @patch('crc.services.protocol_builder.requests.get')

View File

@ -386,15 +386,15 @@ class TestTasksApi(BaseTest):
# Start the workflow. # Start the workflow.
first_task = self.get_workflow_api(workflow).next_task first_task = self.get_workflow_api(workflow).next_task
self.complete_form(workflow, first_task, {"has_bananas": True}) self.complete_form(workflow, first_task, {"has_bananas": True})
workflow = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
self.assertEqual('Task_Num_Bananas', workflow.next_task.name) self.assertEqual('Task_Num_Bananas', workflow_api.next_task.name)
# Trying to re-submit the initial task, and answer differently, should result in an error. # Trying to re-submit the initial task, and answer differently, should result in an error.
self.complete_form(workflow, first_task, {"has_bananas": False}, error_code="invalid_state") self.complete_form(workflow, first_task, {"has_bananas": False}, error_code="invalid_state")
# Go ahead and set the number of bananas. # Go ahead and set the number of bananas.
workflow = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
task = workflow.next_task task = workflow_api.next_task
self.complete_form(workflow, task, {"num_bananas": 4}) self.complete_form(workflow, task, {"num_bananas": 4})
# We are now at the end of the workflow. # We are now at the end of the workflow.
@ -405,19 +405,19 @@ class TestTasksApi(BaseTest):
content_type="application/json") content_type="application/json")
self.assert_success(rv) self.assert_success(rv)
json_data = json.loads(rv.get_data(as_text=True)) json_data = json.loads(rv.get_data(as_text=True))
workflow = WorkflowApiSchema().load(json_data) workflow_api = WorkflowApiSchema().load(json_data)
# Assure the Next Task is the one we just reset the token to be on. # Assure the Next Task is the one we just reset the token to be on.
self.assertEqual("Task_Has_Bananas", workflow.next_task.name) self.assertEqual("Task_Has_Bananas", workflow_api.next_task.name)
# Go ahead and get that workflow one more time, it should still be right. # Go ahead and get that workflow one more time, it should still be right.
workflow = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
# Assure the Next Task is the one we just reset the token to be on. # Assure the Next Task is the one we just reset the token to be on.
self.assertEqual("Task_Has_Bananas", workflow.next_task.name) self.assertEqual("Task_Has_Bananas", workflow_api.next_task.name)
# The next task should be a different value. # The next task should be a different value.
self.complete_form(workflow, workflow.next_task, {"has_bananas": False}) self.complete_form(workflow, workflow_api.next_task, {"has_bananas": False})
workflow = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
self.assertEqual('Task_Why_No_Bananas', workflow.next_task.name) self.assertEqual('Task_Why_No_Bananas', workflow_api.next_task.name)

View File

@ -7,7 +7,7 @@ class TestBooleanDefault(BaseTest):
workflow = self.create_workflow('boolean_default_value') workflow = self.create_workflow('boolean_default_value')
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
set_default_task = workflow_api.next_task set_default_task = workflow_api.next_task
result = self.complete_form(workflow_api, set_default_task, {'yes_no': yes_no}) result = self.complete_form(workflow, set_default_task, {'yes_no': yes_no})
return result return result
def test_boolean_true_string(self): def test_boolean_true_string(self):

View File

@ -7,35 +7,35 @@ class TestWorkflowEnumDefault(BaseTest):
def test_enum_default_from_value_expression(self): def test_enum_default_from_value_expression(self):
workflow = self.create_workflow('enum_value_expression') workflow = self.create_workflow('enum_value_expression')
first_task = self.get_workflow_api(workflow).next_task
self.assertEqual('Activity_UserInput', first_task.name)
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
first_task = workflow_api.next_task
self.assertEqual('Activity_UserInput', first_task.name)
result = self.complete_form(workflow_api, first_task, {'user_input': True}) result = self.complete_form(workflow, first_task, {'user_input': True})
self.assertIn('user_input', result.next_task.data) self.assertIn('user_input', result.next_task.data)
self.assertEqual(True, result.next_task.data['user_input']) self.assertEqual(True, result.next_task.data['user_input'])
self.assertIn('lookup_output', result.next_task.data) self.assertIn('lookup_output', result.next_task.data)
self.assertEqual('black', result.next_task.data['lookup_output']) self.assertEqual('black', result.next_task.data['lookup_output'])
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
self.assertEqual('Activity_PickColor', self.get_workflow_api(workflow_api).next_task.name) self.assertEqual('Activity_PickColor', workflow_api.next_task.name)
self.assertEqual({'value': 'black', 'label': 'Black'}, workflow_api.next_task.data['color_select']) self.assertEqual({'value': 'black', 'label': 'Black'}, workflow_api.next_task.data['color_select'])
# #
workflow = self.create_workflow('enum_value_expression') workflow = self.create_workflow('enum_value_expression')
first_task = self.get_workflow_api(workflow).next_task
self.assertEqual('Activity_UserInput', first_task.name)
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
first_task = workflow_api.next_task
self.assertEqual('Activity_UserInput', first_task.name)
result = self.complete_form(workflow_api, first_task, {'user_input': False}) result = self.complete_form(workflow, first_task, {'user_input': False})
self.assertIn('user_input', result.next_task.data) self.assertIn('user_input', result.next_task.data)
self.assertEqual(False, result.next_task.data['user_input']) self.assertEqual(False, result.next_task.data['user_input'])
self.assertIn('lookup_output', result.next_task.data) self.assertIn('lookup_output', result.next_task.data)
self.assertEqual('white', result.next_task.data['lookup_output']) self.assertEqual('white', result.next_task.data['lookup_output'])
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
self.assertEqual('Activity_PickColor', self.get_workflow_api(workflow_api).next_task.name) self.assertEqual('Activity_PickColor', workflow_api.next_task.name)
self.assertEqual({'value': 'white', 'label': 'White'}, workflow_api.next_task.data['color_select']) self.assertEqual({'value': 'white', 'label': 'White'}, workflow_api.next_task.data['color_select'])
def test_enum_value_expression_and_default(self): def test_enum_value_expression_and_default(self):

View File

@ -18,7 +18,7 @@ class TestFormFieldName(BaseTest):
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
first_task = workflow_api.next_task first_task = workflow_api.next_task
self.complete_form(workflow_api, first_task, {}) self.complete_form(workflow, first_task, {})
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
second_task = workflow_api.next_task second_task = workflow_api.next_task

View File

@ -34,14 +34,13 @@ class TestWorkflowHiddenRequiredField(BaseTest):
first_task = workflow_api.next_task first_task = workflow_api.next_task
self.assertEqual('Activity_Hello', first_task.name) self.assertEqual('Activity_Hello', first_task.name)
workflow_api = self.get_workflow_api(workflow)
self.complete_form(workflow_api, first_task, {}) self.complete_form(workflow, first_task, {})
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
second_task = workflow_api.next_task second_task = workflow_api.next_task
self.assertEqual('Activity_HiddenField', second_task.name) self.assertEqual('Activity_HiddenField', second_task.name)
self.complete_form(workflow_api, second_task, {}) self.complete_form(workflow, second_task, {})
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
# The color field is hidden and required. Make sure we use the default value # The color field is hidden and required. Make sure we use the default value

View File

@ -9,20 +9,20 @@ class TestWorkflowRestart(BaseTest):
workflow = self.create_workflow('message_event') workflow = self.create_workflow('message_event')
first_task = self.get_workflow_api(workflow).next_task
self.assertEqual('Activity_GetData', first_task.name)
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
first_task = workflow_api.next_task
self.assertEqual('Activity_GetData', first_task.name)
result = self.complete_form(workflow_api, first_task, {'formdata': 'asdf'}) result = self.complete_form(workflow, first_task, {'formdata': 'asdf'})
self.assertIn('formdata', result.next_task.data) self.assertIn('formdata', result.next_task.data)
self.assertEqual('asdf', result.next_task.data['formdata']) self.assertEqual('asdf', result.next_task.data['formdata'])
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
self.assertEqual('Activity_HowMany', self.get_workflow_api(workflow_api).next_task.name) self.assertEqual('Activity_HowMany', workflow_api.next_task.name)
# restart with data. should land at beginning with data # restart with data. should land at beginning with data
workflow_api = self.restart_workflow_api(result) workflow_api = self.restart_workflow_api(result)
first_task = self.get_workflow_api(workflow_api).next_task first_task = workflow_api.next_task
self.assertEqual('Activity_GetData', first_task.name) self.assertEqual('Activity_GetData', first_task.name)
self.assertIn('formdata', workflow_api.next_task.data) self.assertIn('formdata', workflow_api.next_task.data)
self.assertEqual('asdf', workflow_api.next_task.data['formdata']) self.assertEqual('asdf', workflow_api.next_task.data['formdata'])
@ -33,21 +33,19 @@ class TestWorkflowRestart(BaseTest):
self.assertEqual('Activity_GetData', first_task.name) self.assertEqual('Activity_GetData', first_task.name)
self.assertNotIn('formdata', workflow_api.next_task.data) self.assertNotIn('formdata', workflow_api.next_task.data)
print('Nice Test')
def test_workflow_restart_on_cancel_notify(self): def test_workflow_restart_on_cancel_notify(self):
workflow = self.create_workflow('message_event') workflow = self.create_workflow('message_event')
study_id = workflow.study_id study_id = workflow.study_id
# Start the workflow. # Start the workflow.
first_task = self.get_workflow_api(workflow).next_task
self.assertEqual('Activity_GetData', first_task.name)
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
self.complete_form(workflow_api, first_task, {'formdata': 'asdf'}) first_task = workflow_api.next_task
self.assertEqual('Activity_GetData', first_task.name)
self.complete_form(workflow, first_task, {'formdata': 'asdf'})
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
self.assertEqual('Activity_HowMany', workflow_api.next_task.name) self.assertEqual('Activity_HowMany', workflow_api.next_task.name)
workflow_api = self.restart_workflow_api(workflow) self.restart_workflow_api(workflow)
study_result = session.query(StudyModel).filter(StudyModel.id == study_id).first() study_result = session.query(StudyModel).filter(StudyModel.id == study_id).first()
self.assertEqual('New Title', study_result.title) self.assertEqual('New Title', study_result.title)
@ -66,17 +64,16 @@ class TestWorkflowRestart(BaseTest):
study_id = workflow.study_id study_id = workflow.study_id
# Start the workflow. # Start the workflow.
first_task = self.get_workflow_api(workflow).next_task
self.assertEqual('Activity_GetData', first_task.name)
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
self.complete_form(workflow_api, first_task, {'formdata': 'asdf'}) first_task = workflow_api.next_task
self.assertEqual('Activity_GetData', first_task.name)
self.complete_form(workflow, first_task, {'formdata': 'asdf'})
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
next_task = workflow_api.next_task next_task = workflow_api.next_task
self.assertEqual('Activity_HowMany', next_task.name) self.assertEqual('Activity_HowMany', next_task.name)
self.complete_form(workflow_api, next_task, {'how_many': 3}) self.complete_form(workflow, next_task, {'how_many': 3})
workflow_api = self.restart_workflow_api(workflow)
study_result = session.query(StudyModel).filter(StudyModel.id == study_id).first() study_result = session.query(StudyModel).filter(StudyModel.id == study_id).first()
self.assertEqual('Beer consumption in the bipedal software engineer', study_result.title) self.assertEqual('Beer consumption in the bipedal software engineer', study_result.title)

View File

@ -9,7 +9,7 @@ class TestValueExpression(BaseTest):
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
first_task = workflow_api.next_task first_task = workflow_api.next_task
self.complete_form(workflow_api, first_task, {'value_expression_value': ''}) self.complete_form(workflow, first_task, {'value_expression_value': ''})
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
second_task = workflow_api.next_task second_task = workflow_api.next_task
@ -26,7 +26,7 @@ class TestValueExpression(BaseTest):
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
first_task = workflow_api.next_task first_task = workflow_api.next_task
self.complete_form(workflow_api, first_task, {'value_expression_value': 'black'}) self.complete_form(workflow, first_task, {'value_expression_value': 'black'})
workflow_api = self.get_workflow_api(workflow) workflow_api = self.get_workflow_api(workflow)
second_task = workflow_api.next_task second_task = workflow_api.next_task