diff --git a/moto/core/utils.py b/moto/core/utils.py index 98d6bdc2..81acdd6d 100644 --- a/moto/core/utils.py +++ b/moto/core/utils.py @@ -23,6 +23,22 @@ def camelcase_to_underscores(argument): return result +def underscores_to_camelcase(argument): + ''' Converts a camelcase param like the_new_attribute to the equivalent + camelcase version like theNewAttribute. Note that the first letter is + NOT capitalized by this function ''' + result = '' + previous_was_underscore = False + for char in argument: + if char != '_': + if previous_was_underscore: + result += char.upper() + else: + result += char + previous_was_underscore = char == '_' + return result + + def method_names_from_class(clazz): # On Python 2, methods are different from functions, and the `inspect` # predicates distinguish between them. On Python 3, methods are just diff --git a/tests/test_core/test_utils.py b/tests/test_core/test_utils.py index 3e483819..6e27e6f4 100644 --- a/tests/test_core/test_utils.py +++ b/tests/test_core/test_utils.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals import sure -from moto.core.utils import camelcase_to_underscores +from moto.core.utils import camelcase_to_underscores, underscores_to_camelcase def test_camelcase_to_underscores(): @@ -12,3 +12,11 @@ def test_camelcase_to_underscores(): } for arg, expected in cases.items(): camelcase_to_underscores(arg).should.equal(expected) + + +def test_underscores_to_camelcase(): + cases = { + "the_new_attribute": "theNewAttribute", + } + for arg, expected in cases.items(): + underscores_to_camelcase(arg).should.equal(expected)