Merge "Modify notification request parameter name"

This commit is contained in:
Zuul 2021-03-18 11:25:48 +00:00 committed by Gerrit Code Review
commit 8af66d413b
3 changed files with 35 additions and 4 deletions

View File

@ -378,8 +378,34 @@ def convert_snakecase_to_camelcase(request_data):
This method takes care only keys in a `dict` or `dicts in a list`. This method takes care only keys in a `dict` or `dicts in a list`.
For simple list with string items, the elements which are actual values For simple list with string items, the elements which are actual values
are ignored during conversion. are ignored during conversion.
Also, Snake case is a notation method that uses underscores to connect
words. For that reason, if the initial word of the key in dict starts
with '_', this function ignore to convert the key.
:param request_data: dict with keys or list with items, in snake_case. :param request_data: dict with keys or list with items, in snake_case.
Example:
Before::
[
{"vnf_lcm_op_occ_id" : "uuid"},
{
"_links" : {
"vnf_lcm_op_occ": {"href": "resource_link"}
}
}
]
After::
[
{"vnfLcmOpOccId": "uuid"},
{
"_links": {
"vnfLcmOpOcc": {"href": "resource_link"}
}
}
]
""" """
def convert(name): def convert(name):
return re.sub('_([a-z])', return re.sub('_([a-z])',
@ -389,7 +415,7 @@ def convert_snakecase_to_camelcase(request_data):
new_dict = {} new_dict = {}
for key, property_value in request_data.items(): for key, property_value in request_data.items():
property_value = convert_snakecase_to_camelcase(property_value) property_value = convert_snakecase_to_camelcase(property_value)
camelcase = convert(key) camelcase = key if key.startswith('_') else convert(key)
new_dict[camelcase] = property_value new_dict[camelcase] = property_value
return new_dict return new_dict

View File

@ -1461,6 +1461,9 @@ class Conductor(manager.Manager):
try: try:
LOG.debug("send_notification start notification[%s]" LOG.debug("send_notification start notification[%s]"
% notification) % notification)
notification = utils.convert_snakecase_to_camelcase(notification)
if (notification.get('notificationType') == if (notification.get('notificationType') ==
'VnfLcmOperationOccurrenceNotification'): 'VnfLcmOperationOccurrenceNotification'):
vnf_lcm_subscriptions = \ vnf_lcm_subscriptions = \

View File

@ -68,9 +68,11 @@ class TestCamelToSnakeCase(testtools.TestCase):
class TestSnakeToCamelCase(testtools.TestCase): class TestSnakeToCamelCase(testtools.TestCase):
def test_convert_snakecase_to_camelcase_dict(self): def test_convert_snakecase_to_camelcase_dict(self):
"""Only the dict keys from list should be converted to camelcase""" """Only the dict keys from list should be converted to camelcase"""
actual_val = utils.convert_snakecase_to_camelcase( data = {"snake_case_key": "snake_case_value",
{"snake_case_key": "snake_case_value"}) "_key": "ignore_key_value"}
expected_val = {"snakeCaseKey": "snake_case_value"} actual_val = utils.convert_snakecase_to_camelcase(data)
expected_val = {"snakeCaseKey": "snake_case_value",
"_key": "ignore_key_value"}
self.assertEqual(expected_val, actual_val) self.assertEqual(expected_val, actual_val)
def test_convert_snakecase_to_camelcase_list_with_dict_items(self): def test_convert_snakecase_to_camelcase_list_with_dict_items(self):