From 116cb7d207a3c6c9098f61af2d723ecb7f64c565 Mon Sep 17 00:00:00 2001 From: David Justo Date: Tue, 14 Jul 2020 20:09:53 -0700 Subject: [PATCH 1/2] serialize falses --- azure/durable_functions/models/OrchestratorState.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure/durable_functions/models/OrchestratorState.py b/azure/durable_functions/models/OrchestratorState.py index fa44655c..3d68c481 100644 --- a/azure/durable_functions/models/OrchestratorState.py +++ b/azure/durable_functions/models/OrchestratorState.py @@ -77,7 +77,7 @@ def to_json(self) -> Dict[str, Any]: json_dict = {} add_attrib(json_dict, self, '_is_done', 'isDone') self._add_actions(json_dict) - if self._output: + if not (self._output is None): json_dict['output'] = self._output if self._error: json_dict['error'] = self._error From 444af3d5b42339d024d6606cdf044f8b8368401b Mon Sep 17 00:00:00 2001 From: David Justo Date: Thu, 23 Jul 2020 18:20:59 -0700 Subject: [PATCH 2/2] added test to prevent regression --- tests/orchestrator/test_serialization.py | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/orchestrator/test_serialization.py diff --git a/tests/orchestrator/test_serialization.py b/tests/orchestrator/test_serialization.py new file mode 100644 index 00000000..affd18ff --- /dev/null +++ b/tests/orchestrator/test_serialization.py @@ -0,0 +1,30 @@ +from tests.test_utils.ContextBuilder import ContextBuilder +from .orchestrator_test_utils \ + import get_orchestration_state_result, assert_orchestration_state_equals, assert_valid_schema +from azure.durable_functions.models.OrchestratorState import OrchestratorState + +def base_expected_state(output=None) -> OrchestratorState: + return OrchestratorState(is_done=False, actions=[], output=output) + +def generator_function(context): + return False + +def test_serialization_of_False(): + """Test that an orchestrator can return False.""" + + context_builder = ContextBuilder("serialize False") + + result = get_orchestration_state_result( + context_builder, generator_function) + + expected_state = base_expected_state(output=False) + + expected_state._is_done = True + expected = expected_state.to_json() + + # Since we're essentially testing the `to_json` functionality, + # we explicitely ensure that the output is set + expected["output"] = False + + assert_valid_schema(result) + assert_orchestration_state_equals(expected, result) \ No newline at end of file