diff options
Diffstat (limited to 'robotframework-onap')
-rw-r--r-- | robotframework-onap/ONAPLibrary/JSON.py | 4 | ||||
-rw-r--r-- | robotframework-onap/ONAPLibrary/JSONPathKeywords.py | 39 | ||||
-rw-r--r-- | robotframework-onap/setup.py | 3 |
3 files changed, 44 insertions, 2 deletions
diff --git a/robotframework-onap/ONAPLibrary/JSON.py b/robotframework-onap/ONAPLibrary/JSON.py index 6eb1e65..1cb67dd 100644 --- a/robotframework-onap/ONAPLibrary/JSON.py +++ b/robotframework-onap/ONAPLibrary/JSON.py @@ -14,6 +14,7 @@ from ONAPLibrary.robotlibcore import HybridCore from ONAPLibrary.JSONKeywords import JSONKeywords +from ONAPLibrary.JSONPathKeywords import JSONPathKeywords class JSON(HybridCore): @@ -22,6 +23,7 @@ class JSON(HybridCore): def __init__(self): self.keyword_implementors = [ - JSONKeywords() + JSONKeywords(), + JSONPathKeywords() ] HybridCore.__init__(self, self.keyword_implementors) diff --git a/robotframework-onap/ONAPLibrary/JSONPathKeywords.py b/robotframework-onap/ONAPLibrary/JSONPathKeywords.py new file mode 100644 index 0000000..22e5e04 --- /dev/null +++ b/robotframework-onap/ONAPLibrary/JSONPathKeywords.py @@ -0,0 +1,39 @@ +# Copyright 2019 AT&T Intellectual Property. 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. +import json + +from robot.api.deco import keyword +from jsonpath_rw import parse + + +class JSONPathKeywords(object): + """JSONPATH is common resource for json path keywords. + """ + + def __init__(self): + super(JSONPathKeywords, self).__init__() + + @keyword + def json_search(self, expression, target): + """JSON Search takes in two params, the first is the jsonpath expression and the second is the json target + which is converted into string if needed and then compares them, returning the matches.""" + + jsonpath_expr = parse(expression) + if isinstance(target, str) or isinstance(target, unicode): + search_json = json.dumps(target) + else: + search_json = target + + results = jsonpath_expr.find(search_json) + return results diff --git a/robotframework-onap/setup.py b/robotframework-onap/setup.py index 192e171..89b72d5 100644 --- a/robotframework-onap/setup.py +++ b/robotframework-onap/setup.py @@ -38,7 +38,8 @@ setup( 'future', 'robotframework-requests', 'kafka-python', - 'urllib3' + 'urllib3', + 'jsonpath-rw' ], # what we need packages=['loadtest', 'vcpeutils', 'ONAPLibrary'], # The name of your scripts package package_dir={ |