From 9dd61c3398f9b4484a38d46fa747603e199646e0 Mon Sep 17 00:00:00 2001 From: Tulio Casagrande Date: Thu, 7 May 2020 23:09:16 -0300 Subject: [PATCH 1/3] Fix null value in ResultPath Fixes aws/aws-step-functions-data-science-sdk-python#45 --- src/stepfunctions/steps/states.py | 2 +- tests/unit/test_steps.py | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/stepfunctions/steps/states.py b/src/stepfunctions/steps/states.py index 9b4e191..fdc7b72 100644 --- a/src/stepfunctions/steps/states.py +++ b/src/stepfunctions/steps/states.py @@ -68,7 +68,7 @@ def to_dict(self): result = {} # Common fields for k, v in self.fields.items(): - if v is not None: + if v is not None or k == 'result_path': k = to_pascalcase(k) if k == to_pascalcase(Field.Parameters.value): result[k] = self._replace_placeholders(v) diff --git a/tests/unit/test_steps.py b/tests/unit/test_steps.py index cc1fab0..cdc630f 100644 --- a/tests/unit/test_steps.py +++ b/tests/unit/test_steps.py @@ -346,4 +346,24 @@ def test_retry_fail_for_unsupported_state(): c1 = Choice('My Choice') with pytest.raises(ValueError): - c1.add_catch(Catch(error_equals=["States.NoChoiceMatched"], next_step=Fail("ChoiceFailed"))) \ No newline at end of file + c1.add_catch(Catch(error_equals=["States.NoChoiceMatched"], next_step=Fail("ChoiceFailed"))) + + +def test_result_path_none(): + task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda', result_path=None) + assert task_state.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:lambda:us-east-1:1234567890:function:StartLambda', + 'ResultPath': None, + 'End': True + } + + +def test_result_path_none_converted_to_null(): + task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda', result_path=None) + assert '"ResultPath": null' in task_state.to_json() + + +def test_default_result_path_not_converted_to_null(): + task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda') + assert '"ResultPath": null' not in task_state.to_json() From bf62ca96259d2d64d4a40b0a608e38b78437962d Mon Sep 17 00:00:00 2001 From: Tulio Casagrande Date: Fri, 8 May 2020 12:22:53 -0300 Subject: [PATCH 2/3] Add unit test covering default ResultPath --- tests/unit/test_steps.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_steps.py b/tests/unit/test_steps.py index cdc630f..fa0b3d0 100644 --- a/tests/unit/test_steps.py +++ b/tests/unit/test_steps.py @@ -351,12 +351,8 @@ def test_retry_fail_for_unsupported_state(): def test_result_path_none(): task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda', result_path=None) - assert task_state.to_dict() == { - 'Type': 'Task', - 'Resource': 'arn:aws:lambda:us-east-1:1234567890:function:StartLambda', - 'ResultPath': None, - 'End': True - } + assert 'ResultPath' in task_state.to_dict() + assert task_state.to_dict()['ResultPath'] is None def test_result_path_none_converted_to_null(): @@ -364,6 +360,11 @@ def test_result_path_none_converted_to_null(): assert '"ResultPath": null' in task_state.to_json() +def test_default_result_path_not_included(): + task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda') + assert 'ResultPath' not in task_state.to_dict() + + def test_default_result_path_not_converted_to_null(): task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda') assert '"ResultPath": null' not in task_state.to_json() From f996e14d8c14ca5c44a099c4aa2bb0805fe59cd1 Mon Sep 17 00:00:00 2001 From: Tulio Casagrande Date: Fri, 8 May 2020 15:28:23 -0300 Subject: [PATCH 3/3] Fix null values in InputPath and OutputPath --- src/stepfunctions/steps/states.py | 3 ++- tests/unit/test_steps.py | 30 ++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/stepfunctions/steps/states.py b/src/stepfunctions/steps/states.py index fdc7b72..b6d81e1 100644 --- a/src/stepfunctions/steps/states.py +++ b/src/stepfunctions/steps/states.py @@ -66,9 +66,10 @@ def _replace_placeholders(self, params): def to_dict(self): result = {} + fields_accepted_as_none = ('result_path', 'input_path', 'output_path') # Common fields for k, v in self.fields.items(): - if v is not None or k == 'result_path': + if v is not None or k in fields_accepted_as_none: k = to_pascalcase(k) if k == to_pascalcase(Field.Parameters.value): result[k] = self._replace_placeholders(v) diff --git a/tests/unit/test_steps.py b/tests/unit/test_steps.py index fa0b3d0..1002238 100644 --- a/tests/unit/test_steps.py +++ b/tests/unit/test_steps.py @@ -349,22 +349,40 @@ def test_retry_fail_for_unsupported_state(): c1.add_catch(Catch(error_equals=["States.NoChoiceMatched"], next_step=Fail("ChoiceFailed"))) -def test_result_path_none(): - task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda', result_path=None) +def test_paths_none(): + task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda', + result_path=None, + input_path=None, + output_path=None) assert 'ResultPath' in task_state.to_dict() assert task_state.to_dict()['ResultPath'] is None + assert 'InputPath' in task_state.to_dict() + assert task_state.to_dict()['InputPath'] is None -def test_result_path_none_converted_to_null(): - task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda', result_path=None) + assert 'OutputPath' in task_state.to_dict() + assert task_state.to_dict()['OutputPath'] is None + + +def test_paths_none_converted_to_null(): + task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda', + result_path=None, + input_path=None, + output_path=None) assert '"ResultPath": null' in task_state.to_json() + assert '"InputPath": null' in task_state.to_json() + assert '"OutputPath": null' in task_state.to_json() -def test_default_result_path_not_included(): +def test_default_paths_not_included(): task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda') assert 'ResultPath' not in task_state.to_dict() + assert 'InputPath' not in task_state.to_dict() + assert 'OutputPath' not in task_state.to_dict() -def test_default_result_path_not_converted_to_null(): +def test_default_paths_not_converted_to_null(): task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda') assert '"ResultPath": null' not in task_state.to_json() + assert '"InputPath": null' not in task_state.to_json() + assert '"OutputPath": null' not in task_state.to_json()