Skip to content

Commit 3117635

Browse files
committed
refactor orchestration tests
1 parent 7e77ba2 commit 3117635

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

azure/durable_functions/models/OrchestratorState.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ def to_json(self) -> Dict[str, Any]:
2929
action_dict['functionName'] = action_obj.functionName
3030
if hasattr(action_obj, 'input'):
3131
action_dict['input'] = action_obj.input
32-
3332
action_result_list.append(action_dict)
3433
json_dict['actions'].append(action_result_list)
35-
json_dict['output'] = self.output
36-
json_dict['error'] = self.error
37-
json_dict['customStatus'] = self.customStatus
34+
if self.output:
35+
json_dict['output'] = self.output
36+
if self.error:
37+
json_dict['error'] = self.error
38+
if self.customStatus:
39+
json_dict['customStatus'] = self.customStatus
3840
return json_dict
3941

4042
def to_json_string(self) -> str:

tests/models/test_OrchestrationState.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ def test_empty_state_to_json_string():
99
actions: List[List[IAction]] = []
1010
state = OrchestratorState(isDone=False, actions=actions, output=None, error=None, customStatus=None)
1111
result = state.to_json_string()
12-
expected_result = ('{"isDone": false, "actions": [], "output": null, "error": null, '
13-
'"customStatus": null}')
12+
expected_result = '{"isDone": false, "actions": []}'
1413
assert expected_result == result
1514

1615

@@ -21,5 +20,5 @@ def test_single_action_state_to_json_string():
2120
state = OrchestratorState(isDone=False, actions=actions, output=None, error=None, customStatus=None)
2221
result = state.to_json_string()
2322
expected_result = ('{"isDone": false, "actions": [[{"actionType": 0, "functionName": "MyFunction", "input": '
24-
'"AwesomeInput"}]], "output": null, "error": null, "customStatus": null}')
23+
'"AwesomeInput"}]]}')
2524
assert expected_result == result

tests/orchestrator/test_chaining_orchestrator.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,25 @@ def generator_function(context):
2424
(HANDLE_TWO, STATE_TWO),
2525
(HANDLE_THREE, STATE_THREE),
2626
(HANDLE_FOUR, STATE_FOUR)])
27-
def test_initial_activity_one(context, output_state):
27+
def test_orchestration_state_output(context, output_state):
2828
orchestrator = Orchestrator(generator_function)
2929
result = json.loads(orchestrator.handle(context))
3030
expected = json.loads(output_state)
31-
assert expected.get("isDone") == result.get("isDone")
31+
assert_attribute_equal(expected, result, "isDone")
32+
assert_actions_are_equal(expected, result)
33+
assert_attribute_equal(expected, result, "output")
34+
assert_attribute_equal(expected, result, "error")
35+
assert_attribute_equal(expected, result, "customStatus")
36+
37+
38+
def assert_attribute_equal(expected, result, attribute):
39+
if hasattr(expected, attribute):
40+
assert expected.get(attribute) == result.get(attribute)
41+
else:
42+
assert not hasattr(result, attribute)
43+
44+
45+
def assert_actions_are_equal(expected, result):
3246
expected_actions = expected.get("actions")
3347
result_actions = result.get("actions")
3448
assert len(expected_actions) == len(result_actions)

0 commit comments

Comments
 (0)