mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-11 03:31:29 -07:00
[cloud] Improve snake <-> camel conversion for AWS utils (#31400)
Allow CamelCase version of snake_dict_to_camel_dict (currently only dromedaryCase is supported) Add reversible option to camel_dict_to_snake_dict Add tests for both of these options
This commit is contained in:
parent
2425374fdd
commit
15a58d498d
2 changed files with 69 additions and 19 deletions
|
@ -17,7 +17,7 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.module_utils.ec2 import _camel_to_snake
|
||||
from ansible.module_utils.ec2 import _camel_to_snake, _snake_to_camel
|
||||
|
||||
EXPECTED_SNAKIFICATION = {
|
||||
'alllower': 'alllower',
|
||||
|
@ -29,9 +29,35 @@ EXPECTED_SNAKIFICATION = {
|
|||
'PLURALs': 'plurals'
|
||||
}
|
||||
|
||||
EXPECTED_REVERSIBLE = {
|
||||
'TwoWords': 'two_words',
|
||||
'AllUpperAtEND': 'all_upper_at_e_n_d',
|
||||
'AllUpperButPLURALs': 'all_upper_but_p_l_u_r_a_ls',
|
||||
'TargetGroupARNs': 'target_group_a_r_ns',
|
||||
'HTTPEndpoints': 'h_t_t_p_endpoints',
|
||||
'PLURALs': 'p_l_u_r_a_ls'
|
||||
}
|
||||
|
||||
|
||||
class CamelToSnakeTestCase(unittest.TestCase):
|
||||
|
||||
def test_camel_to_snake(self):
|
||||
for (k, v) in EXPECTED_SNAKIFICATION.items():
|
||||
self.assertEqual(_camel_to_snake(k), v)
|
||||
|
||||
def test_reversible_camel_to_snake(self):
|
||||
for (k, v) in EXPECTED_REVERSIBLE.items():
|
||||
self.assertEqual(_camel_to_snake(k, reversible=True), v)
|
||||
|
||||
|
||||
class SnakeToCamelTestCase(unittest.TestCase):
|
||||
|
||||
def test_snake_to_camel_reversed(self):
|
||||
for (k, v) in EXPECTED_REVERSIBLE.items():
|
||||
self.assertEqual(_snake_to_camel(v, capitalize_first=True), k)
|
||||
|
||||
|
||||
class CamelToSnakeAndBackTestCase(unittest.TestCase):
|
||||
def test_camel_to_snake_and_back(self):
|
||||
for (k, v) in EXPECTED_REVERSIBLE.items():
|
||||
self.assertEqual(_snake_to_camel(_camel_to_snake(k, reversible=True), capitalize_first=True), k)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue