From 42dbe88133883bc83af504c268dd00bb33147c0b Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Sat, 7 Nov 2015 15:46:07 -0800 Subject: [PATCH] Formerly, jsonpath_mini supported extraction by subscript number, or by dictionary element. It was not possible to simply convert the raw body to JSON and test against that. This addition allows one to do that. --- pyresttest/validators.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pyresttest/validators.py b/pyresttest/validators.py index 32297394..31524c75 100644 --- a/pyresttest/validators.py +++ b/pyresttest/validators.py @@ -237,12 +237,14 @@ def query_dictionary(query, dictionary, delimiter='.'): # http://stackoverflow.com/questions/7320319/xpath-like-query-for-nested-python-dictionaries try: - for x in query.strip(delimiter).split(delimiter): - try: - x = int(x) - dictionary = dictionary[x] - except ValueError: - dictionary = dictionary[x] + stripped_query = query.strip(delimiter) + if stripped_query: + for x in stripped_query.split(delimiter): + try: + x = int(x) + dictionary = dictionary[x] + except ValueError: + dictionary = dictionary[x] except: return None return dictionary