Recursively compare dictionaries in cord-api test utils
Change-Id: I5c7108e73916aca67490891d42df564f35fddc61
diff --git a/src/test/cord-api/Framework/utils/utils.py b/src/test/cord-api/Framework/utils/utils.py
index c807189..04c94f9 100644
--- a/src/test/cord-api/Framework/utils/utils.py
+++ b/src/test/cord-api/Framework/utils/utils.py
@@ -28,25 +28,35 @@
dict2 = retrieved data from GET method
returns True if contents of dict1 exists in dict2
'''
-
- @staticmethod
- def compare_dict(dict1, dict2):
- print "input_data", dict1
+ def compare_dict(self, dict1, dict2):
+ print "input data", dict1
print "get data", dict2
if dict1 == None or dict2 == None:
return False
-
if type(dict1) is not dict or type(dict2) is not dict:
return False
+ if dict1 == {}:
+ return True
+ return self.compare_dict_recursive(dict1, dict2)
+ '''
+ @method compare_dict_recursive
+ @Description: recursive function to validate if dict1 is a subset of dict2
+ returns True if contents of dict1 exists in dict2
+ '''
+ def compare_dict_recursive(self, dict1, dict2):
for key1,value1 in dict1.items():
- try:
- if key1 in dict2:
- for key2, value2 in value1.items():
- if value2 != dict2[key1][key2]:
- return False
- except:
- print "Additional items"
+ if key1 not in dict2.keys():
+ print "Missing key", key1, "in dict2"
+ return False
+ value2 = dict2[key1]
+ if type(value1) is dict and type(value2) is dict:
+ if not self.compare_dict_recursive(value1, value2):
+ return False
+ else:
+ if value2 != value1:
+ print "Values of key", key1, "in two dicts are not equal"
+ return False
return True
'''