]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Tolerate missing keys in reformat_dict_keys
authorSteve Baker <sbaker@redhat.com>
Wed, 20 Mar 2013 21:42:28 +0000 (10:42 +1300)
committerSteve Baker <sbaker@redhat.com>
Wed, 20 Mar 2013 21:50:35 +0000 (10:50 +1300)
For validate, some keys are optional but still need mapping
if they are there.

Helps bug #1157537

Change-Id: Ib29cd99979a84892a98117c607651ea4c352e3d1

heat/api/aws/utils.py
heat/tests/test_api_aws.py

index dd43e79313e2addf4cc1ce9c9c037a5c81eca8ba..9b3a6ecb8921886ccb97c17e08f1c056ceee0500 100644 (file)
@@ -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])
index 920454b767742c435f927aa2e9f0d943a74647ae..507b4dcb3657c96e180806d18c07e3a6ea2941d4 100644 (file)
@@ -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"