From b090e31e004637ca8c3751ca35af1afc8f7a796c Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Wed, 3 Feb 2021 09:50:16 -0500 Subject: [PATCH 1/2] This fixes 2 issues with setting boolean defaults - If the default was False, we failed an early test and returned None. We now only return None if default is None - We have a better test for deciding if the default value we return should be True or False. We used to return True if the value was the string 'false'. --- crc/services/workflow_service.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index dce8118f..e148d039 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -251,7 +251,9 @@ class WorkflowService(object): default = result # If no default exists, return None - if not default: return None + # Note: if default is False, we don't want to execute this code + if default is None: + return None if field.type == "enum" and not has_lookup: default_option = next((obj for obj in field.options if obj.id == default), None) @@ -278,7 +280,10 @@ class WorkflowService(object): elif field.type == "long": return int(default) elif field.type == 'boolean': - return bool(default) + default = str(default).lower() + if default == 'true' or default == 't': + return True + return False else: return default From 1247744463f6628149ab41237111f84a72b4a718 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Wed, 3 Feb 2021 09:50:37 -0500 Subject: [PATCH 2/2] Test and workflow for new code. --- .../boolean_default_value.bpmn | 89 +++++++++++++++++++ .../workflow/test_workflow_boolean_default.py | 71 +++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 tests/data/boolean_default_value/boolean_default_value.bpmn create mode 100644 tests/workflow/test_workflow_boolean_default.py diff --git a/tests/data/boolean_default_value/boolean_default_value.bpmn b/tests/data/boolean_default_value/boolean_default_value.bpmn new file mode 100644 index 00000000..4f820e65 --- /dev/null +++ b/tests/data/boolean_default_value/boolean_default_value.bpmn @@ -0,0 +1,89 @@ + + + + + Flow_1x41riu + + + + + + + + + + + + Flow_0zp5mss + Flow_0m31ypa + + + + <H1>Good Bye</H1> +<div><span>Pick One: {% if pick_one %}{{ pick_one}}{% endif %} </span></div> + + Flow_0m31ypa + Flow_0f3gndz + + + Flow_0f3gndz + + + + + <H1>Hello</H1> + Flow_1x41riu + Flow_1i32jb7 + + + + + Flow_1i32jb7 + Flow_0zp5mss + if not 'yes_no' in globals(): + yes_no = False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/workflow/test_workflow_boolean_default.py b/tests/workflow/test_workflow_boolean_default.py new file mode 100644 index 00000000..bd97d2ec --- /dev/null +++ b/tests/workflow/test_workflow_boolean_default.py @@ -0,0 +1,71 @@ +from tests.base_test import BaseTest + + +class TestBooleanDefault(BaseTest): + + def do_test(self, yes_no): + workflow = self.create_workflow('boolean_default_value') + workflow_api = self.get_workflow_api(workflow) + first_task = workflow_api.next_task + result = self.complete_form(workflow_api, first_task, {'yes_no': yes_no}) + return result + + def test_boolean_true_string(self): + + yes_no = 'True' + result = self.do_test(yes_no) + self.assertEqual(True, result.next_task.data['pick_one']) + + def test_boolean_true_string_lower(self): + + yes_no = 'true' + result = self.do_test(yes_no) + self.assertEqual(True, result.next_task.data['pick_one']) + + def test_boolean_t_string(self): + + yes_no = 'T' + result = self.do_test(yes_no) + self.assertEqual(True, result.next_task.data['pick_one']) + + def test_boolean_t_string_lower(self): + + yes_no = 't' + result = self.do_test(yes_no) + self.assertEqual(True, result.next_task.data['pick_one']) + + def test_boolean_true(self): + + yes_no = True + result = self.do_test(yes_no) + self.assertEqual(True, result.next_task.data['pick_one']) + + def test_boolean_false_string(self): + + yes_no = 'False' + result = self.do_test(yes_no) + self.assertEqual(False, result.next_task.data['pick_one']) + + def test_boolean_false_string_lower(self): + + yes_no = 'false' + result = self.do_test(yes_no) + self.assertEqual(False, result.next_task.data['pick_one']) + + def test_boolean_f_string(self): + + yes_no = 'F' + result = self.do_test(yes_no) + self.assertEqual(False, result.next_task.data['pick_one']) + + def test_boolean_f_string_lower(self): + + yes_no = 'f' + result = self.do_test(yes_no) + self.assertEqual(False, result.next_task.data['pick_one']) + + def test_boolean_false(self): + + yes_no = False + result = self.do_test(yes_no) + self.assertEqual(False, result.next_task.data['pick_one'])