summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/tests/validation_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'snaps/openstack/tests/validation_utils.py')
-rw-r--r--snaps/openstack/tests/validation_utils.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/snaps/openstack/tests/validation_utils.py b/snaps/openstack/tests/validation_utils.py
new file mode 100644
index 0000000..7c9bd7f
--- /dev/null
+++ b/snaps/openstack/tests/validation_utils.py
@@ -0,0 +1,69 @@
+# Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs")
+# and others. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from neutronclient.v2_0.client import _DictWithMeta
+
+__author__ = 'spisarski'
+
+
+def objects_equivalent(obj1, obj2):
+ """
+ Returns true if both objects are equivalent
+ :param obj1:
+ :param obj2:
+ :return: T/F
+ """
+ if obj1 is None and obj2 is None:
+ return True
+ if type(obj1) is dict or type(obj1) is _DictWithMeta:
+ return dicts_equivalent(obj1, obj2)
+ elif type(obj1) is list:
+ return lists_equivalent(obj1, obj2)
+ else:
+ return obj1 == obj2
+
+
+def dicts_equivalent(dict1, dict2):
+ """
+ Returns true when each key/value pair is equal
+ :param dict1: dict 1
+ :param dict2: dict 2
+ :return: T/F
+ """
+ if (type(dict1) is dict or type(dict1) is _DictWithMeta) and (type(dict2) is dict or type(dict2) is _DictWithMeta):
+ for key, value1 in dict1.iteritems():
+ if not objects_equivalent(value1, dict2.get(key)):
+ return False
+ return True
+ return False
+
+
+def lists_equivalent(list1, list2):
+ """
+ Returns true when an item in list1 is also contained in list2
+ :param list1: list 1
+ :param list2: list 2
+ :return: T/F
+ """
+ if len(list1) == len(list2) and type(list1) is list and type(list2) is list:
+ for item1 in list1:
+ has_equivalent = False
+ for item2 in list2:
+ has_equivalent = objects_equivalent(item1, item2)
+ if has_equivalent:
+ break
+ if not has_equivalent:
+ return False
+ return True
+ return False