1 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from robot.api.deco import keyword
17 from deepdiff import DeepDiff
20 class JSONKeywords(object):
21 """JSON is common resource for simple json helper keywords.
25 super(JSONKeywords, self).__init__()
28 def json_equals(self, left, right):
29 """JSON Equals takes in two strings or json objects, converts them into json if needed and then compares them,
30 returning if they are equal or not."""
31 if isinstance(left, str) or isinstance(left, unicode):
32 left_json = json.loads(left)
35 if isinstance(right, str) or isinstance(right, unicode):
36 right_json = json.loads(right)
40 ddiff = DeepDiff(left_json, right_json, ignore_order=True)
47 def make_list_into_dict(self, dict_list, key):
48 """ Converts a list of dicts that contains a field that has a unique key into a dict of dicts """
50 if isinstance(dict_list, list):
51 for thisDict in dict_list:
57 def find_element_in_array(self, searched_array, key, value):
58 """ Takes in an array and a key value, it will return the items in the array that has a key and value that
59 matches what you pass in """
61 for item in searched_array:
63 if item[key] == value: