-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(261): Adds parameter to descend into lists when scrubbing None p… (
#262) * feat(261): Adds parameter to descend into lists when scrubbing None params * Switch default of descend_into_lists to False to avoid a potentially breaking change * ensure descend_into_lists is passed on recursion * Update changelog * Update tests to ensure that the default behaviour of descend_into_lists is also tested Co-authored-by: Mark Chappell <[email protected]>
- Loading branch information
Showing
4 changed files
with
65 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
minor_changes: | ||
- module_utils/core - add parameter ``descend_into_lists`` to ``scrub_none_parameters`` helper function (https://github.com/ansible-collections/amazon.aws/pull/262). |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 57 additions & 25 deletions
82
tests/unit/module_utils/core/test_scrub_none_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,88 @@ | ||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
from ansible_collections.amazon.aws.plugins.module_utils.core import scrub_none_parameters | ||
import pytest | ||
|
||
from ansible_collections.amazon.aws.plugins.module_utils.core import scrub_none_parameters | ||
|
||
scrub_none_test_data = [ | ||
(dict(), | ||
dict() | ||
(dict(), # Input | ||
dict(), # Output with descend_into_lists=False | ||
dict(), # Output with descend_into_lists=True | ||
), | ||
(dict(param1=None, param2=None), | ||
dict(), | ||
dict(), | ||
), | ||
(dict(param1='something'), | ||
dict(param1='something') | ||
dict(param1='something'), | ||
dict(param1='something'), | ||
), | ||
(dict(param1=False), | ||
dict(param1=False) | ||
dict(param1=False), | ||
dict(param1=False), | ||
), | ||
(dict(param1=None, param2=[]), | ||
dict(param2=[]), | ||
dict(param2=[]), | ||
), | ||
(dict(param1=None, param2=["list_value"]), | ||
dict(param2=["list_value"]), | ||
dict(param2=["list_value"]), | ||
), | ||
(dict(param1='something', param2='something_else'), | ||
dict(param1='something', param2='something_else') | ||
dict(param1='something', param2='something_else'), | ||
dict(param1='something', param2='something_else'), | ||
), | ||
(dict(param1='something', param2=dict()), | ||
dict(param1='something', param2=dict()) | ||
dict(param1='something', param2=dict()), | ||
dict(param1='something', param2=dict()), | ||
), | ||
(dict(param1='something', param2=None), | ||
dict(param1='something') | ||
dict(param1='something'), | ||
dict(param1='something'), | ||
), | ||
(dict(param1='something', param2=None, param3=None), | ||
dict(param1='something') | ||
dict(param1='something'), | ||
dict(param1='something'), | ||
), | ||
(dict(param1='something', param2=None, param3=None, param4='something_else'), | ||
dict(param1='something', param4='something_else') | ||
), | ||
(dict(param1=dict(sub_param1='something', sub_param2=None), param2=None, param3=None, param4='something_else'), | ||
dict(param1=dict(sub_param1='something'), param4='something_else') | ||
dict(param1='something', param4='something_else'), | ||
dict(param1='something', param4='something_else'), | ||
), | ||
(dict(param1=dict(sub_param1='something', sub_param2=dict(sub_sub_param1='another_thing')), param2=None, param3=None, param4='something_else'), | ||
dict(param1=dict(sub_param1='something', sub_param2=dict(sub_sub_param1='another_thing')), param4='something_else') | ||
dict(param1=dict(sub_param1='something', sub_param2=dict(sub_sub_param1='another_thing')), param4='something_else'), | ||
dict(param1=dict(sub_param1='something', sub_param2=dict(sub_sub_param1='another_thing')), param4='something_else'), | ||
), | ||
(dict(param1=dict(sub_param1='something', sub_param2=dict()), param2=None, param3=None, param4='something_else'), | ||
dict(param1=dict(sub_param1='something', sub_param2=dict()), param4='something_else') | ||
dict(param1=dict(sub_param1='something', sub_param2=dict()), param4='something_else'), | ||
dict(param1=dict(sub_param1='something', sub_param2=dict()), param4='something_else'), | ||
), | ||
(dict(param1=dict(sub_param1='something', sub_param2=False), param2=None, param3=None, param4='something_else'), | ||
dict(param1=dict(sub_param1='something', sub_param2=False), param4='something_else') | ||
dict(param1=dict(sub_param1='something', sub_param2=False), param4='something_else'), | ||
dict(param1=dict(sub_param1='something', sub_param2=False), param4='something_else'), | ||
), | ||
(dict(param1=None, param2=None), | ||
dict() | ||
(dict(param1=[dict(sub_param1='my_dict_nested_in_a_list_1', sub_param2='my_dict_nested_in_a_list_2')], param2=[]), | ||
dict(param1=[dict(sub_param1='my_dict_nested_in_a_list_1', sub_param2='my_dict_nested_in_a_list_2')], param2=[]), | ||
dict(param1=[dict(sub_param1='my_dict_nested_in_a_list_1', sub_param2='my_dict_nested_in_a_list_2')], param2=[]), | ||
), | ||
(dict(param1=[dict(sub_param1='my_dict_nested_in_a_list_1', sub_param2=None)], param2=[]), | ||
dict(param1=[dict(sub_param1='my_dict_nested_in_a_list_1', sub_param2=None)], param2=[]), | ||
dict(param1=[dict(sub_param1='my_dict_nested_in_a_list_1')], param2=[]), | ||
), | ||
(dict(param1=[dict(sub_param1=[dict(sub_sub_param1=None)], sub_param2=None)], param2=[]), | ||
dict(param1=[dict(sub_param1=[dict(sub_sub_param1=None)], sub_param2=None)], param2=[]), | ||
dict(param1=[dict(sub_param1=[dict()])], param2=[]), | ||
), | ||
(dict(param1=[dict(sub_param1=[dict(sub_sub_param1=None)], sub_param2=None)], param2=None), | ||
dict(param1=[dict(sub_param1=[dict(sub_sub_param1=None)], sub_param2=None)]), | ||
dict(param1=[dict(sub_param1=[dict()])]), | ||
), | ||
(dict(param1=None, param2=[]), | ||
dict(param2=[]) | ||
) | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("input_params, output_params", scrub_none_test_data) | ||
def test_scrub_none_parameters(input_params, output_params): | ||
|
||
assert scrub_none_parameters(input_params) == output_params | ||
@pytest.mark.parametrize("input_params, output_params_no_descend, output_params_descend", scrub_none_test_data) | ||
def test_scrub_none_parameters(input_params, output_params_no_descend, output_params_descend): | ||
assert scrub_none_parameters(input_params) == output_params_no_descend | ||
assert scrub_none_parameters(input_params, descend_into_lists=False) == output_params_no_descend | ||
assert scrub_none_parameters(input_params, descend_into_lists=True) == output_params_descend |