From 39e874504f89c1c3bbe311d898c049b3ae11bdcd Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Wed, 10 Feb 2021 14:35:58 -0500 Subject: [PATCH] We now allow value_expression to evaluate to an empty string ("") so that we *do not* set a default value for enums in some cases. This was causing an error because "" was not an option for the enum. --- crc/services/workflow_service.py | 2 + .../test_value_expression.bpmn | 89 +++++++++++++++++++ .../test_workflow_value_expression.py | 31 +++++++ 3 files changed, 122 insertions(+) create mode 100644 tests/data/test_value_expression/test_value_expression.bpmn create mode 100644 tests/workflow/test_workflow_value_expression.py diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index 74d070c0..ba5c4cd3 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -256,6 +256,8 @@ class WorkflowService(object): return None if field.type == "enum" and not has_lookup: + if isinstance(default, str) and default.strip() == '': + return default_option = next((obj for obj in field.options if obj.id == default), None) if not default_option: raise ApiError.from_task("invalid_default", "You specified a default value that does not exist in " diff --git a/tests/data/test_value_expression/test_value_expression.bpmn b/tests/data/test_value_expression/test_value_expression.bpmn new file mode 100644 index 00000000..ee6c09aa --- /dev/null +++ b/tests/data/test_value_expression/test_value_expression.bpmn @@ -0,0 +1,89 @@ + + + + + Flow_1nc3qi5 + + + + + + <H1>Hello</H1> + Flow_1nc3qi5 + Flow_1t2lo17 + + + Flow_1t2lo17 + Flow_1hhfj67 + if not 'value_expression_value' in globals(): + value_expression_value = "" + + + + + + + + + + + + + + Flow_1hhfj67 + Flow_1skkg5a + + + + <H1>Good Bye</H1> + Flow_1skkg5a + Flow_057as2q + + + Flow_057as2q + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/workflow/test_workflow_value_expression.py b/tests/workflow/test_workflow_value_expression.py new file mode 100644 index 00000000..e059dfef --- /dev/null +++ b/tests/workflow/test_workflow_value_expression.py @@ -0,0 +1,31 @@ +from tests.base_test import BaseTest + + +class TestValueExpression(BaseTest): + + def test_value_expression_no_default(self): + + workflow = self.create_workflow('test_value_expression') + + workflow_api = self.get_workflow_api(workflow) + first_task = workflow_api.next_task + self.complete_form(workflow_api, first_task, {'value_expression_value': ''}) + + workflow_api = self.get_workflow_api(workflow) + second_task = workflow_api.next_task + self.assertEqual('', second_task.data['value_expression_value']) + self.assertNotIn('color', second_task.data) + + def test_value_expression_with_default(self): + + workflow = self.create_workflow('test_value_expression') + + workflow_api = self.get_workflow_api(workflow) + first_task = workflow_api.next_task + self.complete_form(workflow_api, first_task, {'value_expression_value': 'black'}) + + workflow_api = self.get_workflow_api(workflow) + second_task = workflow_api.next_task + self.assertEqual('black', second_task.data['value_expression_value']) + self.assertIn('color', second_task.data) + self.assertEqual('black', second_task.data['color']['value'])