Tolerate missing keys in reformat_dict_keys
For validate, some keys are optional but still need mapping if they are there. Helps bug #1157537 Change-Id: Ib29cd99979a84892a98117c607651ea4c352e3d1
This commit is contained in:
parent
8c6dfdea9b
commit
a924df95b5
@ -111,4 +111,5 @@ def reformat_dict_keys(keymap={}, inputdict={}):
|
||||
'''
|
||||
Utility function for mapping one dict format to another
|
||||
'''
|
||||
return dict([(outk, inputdict[ink]) for ink, outk in keymap.items()])
|
||||
return dict([(outk, inputdict[ink]) for ink, outk in keymap.items()
|
||||
if ink in inputdict])
|
||||
|
@ -181,6 +181,13 @@ class AWSCommon(unittest.TestCase):
|
||||
result = api_utils.reformat_dict_keys(keymap, data)
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_reformat_dict_keys_missing(self):
|
||||
keymap = {"foo": "bar", "foo2": "bar2"}
|
||||
data = {"foo": 123}
|
||||
expected = {"bar": 123}
|
||||
result = api_utils.reformat_dict_keys(keymap, data)
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def setUp(self):
|
||||
print "setup complete"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user