summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDR695H <dr695h@att.com>2019-07-01 14:33:37 -0400
committerDR695H <dr695h@att.com>2019-07-01 14:39:14 -0400
commit03dadb9b9ce5c8386079bd47c54cde17f39382c4 (patch)
tree2f8336ef5c6427c7b958181a8fe3f21ab5cec3e5
parent205db3c1a955f9e96776019deb2922fd208557a7 (diff)
support json path searching
Issue-ID: TEST-172 Change-Id: Id5a355ca0148efb97065c0a5aacd53ddfd11818d Signed-off-by: DR695H <dr695h@att.com>
-rw-r--r--robotframework-onap/ONAPLibrary/JSON.py4
-rw-r--r--robotframework-onap/ONAPLibrary/JSONPathKeywords.py39
-rw-r--r--robotframework-onap/setup.py3
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={