Skip to content

Commit

Permalink
Merge pull request #97 from Orange-OpenSource/fix/jsonpath-parse-extr…
Browse files Browse the repository at this point in the history
…a-dot

Parse extra dot in jsonpath expression
  • Loading branch information
fabricereix authored Nov 28, 2020
2 parents 0ca127f + 842f3f6 commit 6d5239a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 35 deletions.
2 changes: 1 addition & 1 deletion integration/tests/assert_json.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="hurl-file"><div class="hurl-entry"><div class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line section-header">[Asserts]</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.success"</span> <span class="predicate-type">equals</span> <span class="boolean">false</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.success"</span> not <span class="predicate-type">equals</span> <span class="null">null</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.success"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors"</span> <span class="predicate-type">equals</span> <span class="number">2</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.warnings"</span> <span class="predicate-type">equals</span> <span class="number">0</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.toto"</span> not <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.warnings"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.warnings"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0]"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0].id"</span> <span class="predicate-type">equals</span> <span class="string">"error1"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0]['id']"</span> <span class="predicate-type">equals</span> <span class="string">"error1"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type">equals</span> <span class="number">1.5</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type">less-than-or-equal</span> <span class="number">2.0</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type">less-than</span> <span class="number">2</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.nullable"</span> <span class="predicate-type">equals</span> <span class="null">null</span></span><span class="line"></span><span class="line">{<span class="line"> "success": false,</span><span class="line"> "errors": [{"id":"error1"},{"id":"error2"}],</span><span class="line"> "warnings": [],</span><span class="line"> "duration": 1.5,</span><span class="line"> "tags": ["test"],</span><span class="line"> "nullable": null</span><span class="line">}</span></div></div><div class="hurl-entry"><div class="request"><span class="line"></span><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json/index</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line section-header">[Captures]</span></span><span class="line">index<span>:</span> <span class="query-type">status</span></span></div></div><div class="hurl-entry"><div class="request"><span class="line"></span><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line section-header">[Asserts]</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[{{index}}].id"</span> <span class="predicate-type">equals</span> <span class="string">"error2"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags"</span> <span class="predicate-type">includes</span> <span class="string">"test"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags"</span> not <span class="predicate-type">includes</span> <span class="string">"prod"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags"</span> not <span class="predicate-type">includes</span> <span class="null">null</span></span></div></div><span class="line"></span></div>
<div class="hurl-file"><div class="hurl-entry"><div class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line section-header">[Asserts]</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.success"</span> <span class="predicate-type">equals</span> <span class="boolean">false</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.success"</span> not <span class="predicate-type">equals</span> <span class="null">null</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.success"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors"</span> <span class="predicate-type">equals</span> <span class="number">2</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.warnings"</span> <span class="predicate-type">equals</span> <span class="number">0</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.toto"</span> not <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.warnings"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.warnings"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0]"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0].id"</span> <span class="predicate-type">equals</span> <span class="string">"error1"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0]['id']"</span> <span class="predicate-type">equals</span> <span class="string">"error1"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type">equals</span> <span class="number">1.5</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type">less-than-or-equal</span> <span class="number">2.0</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type">less-than</span> <span class="number">2</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.nullable"</span> <span class="predicate-type">equals</span> <span class="null">null</span></span><span class="line"></span><span class="line">{<span class="line"> "success": false,</span><span class="line"> "errors": [{"id":"error1"},{"id":"error2"}],</span><span class="line"> "warnings": [],</span><span class="line"> "duration": 1.5,</span><span class="line"> "tags": ["test"],</span><span class="line"> "nullable": null</span><span class="line">}</span></div></div><div class="hurl-entry"><div class="request"><span class="line"></span><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json/index</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line section-header">[Captures]</span></span><span class="line">index<span>:</span> <span class="query-type">status</span></span></div></div><div class="hurl-entry"><div class="request"><span class="line"></span><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line section-header">[Asserts]</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[{{index}}].id"</span> <span class="predicate-type">equals</span> <span class="string">"error2"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags"</span> <span class="predicate-type">includes</span> <span class="string">"test"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags"</span> not <span class="predicate-type">includes</span> <span class="string">"prod"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags"</span> not <span class="predicate-type">includes</span> <span class="null">null</span></span></div></div><div class="hurl-entry"><div class="request"><span class="line"></span><span class="line"></span><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json/list</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line section-header">[Asserts]</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$"</span> <span class="predicate-type">equals</span> <span class="number">2</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.[0].name"</span> <span class="predicate-type">equals</span> <span class="string">"Bob"</span></span><span class="line"><span class="query-type">jsonpath</span> <span class="string">"$[0].name"</span> <span class="predicate-type">equals</span> <span class="string">"Bob"</span></span></div></div></div>
7 changes: 7 additions & 0 deletions integration/tests/assert_json.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ jsonpath "$.tags" includes "test"
jsonpath "$.tags" not includes "prod"
jsonpath "$.tags" not includes null


GET http://localhost:8000/assert-json/list
HTTP/1.0 200
[Asserts]
jsonpath "$" countEquals 2
jsonpath "$.[0].name" equals "Bob"
jsonpath "$[0].name" equals "Bob"
2 changes: 1 addition & 1 deletion integration/tests/assert_json.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/assert-json"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"jsonpath","expr":"$.success"},"predicate":{"type":"equal","value":false}},{"query":{"type":"jsonpath","expr":"$.success"},"predicate":{"not":true,"type":"equal","value":null}},{"query":{"type":"jsonpath","expr":"$.success"},"predicate":{"type":"exist"}},{"query":{"type":"jsonpath","expr":"$.errors"},"predicate":{"type":"count","value":2}},{"query":{"type":"jsonpath","expr":"$.warnings"},"predicate":{"type":"count","value":0}},{"query":{"type":"jsonpath","expr":"$.toto"},"predicate":{"not":true,"type":"exist"}},{"query":{"type":"jsonpath","expr":"$.warnings"},"predicate":{"type":"exist"}},{"query":{"type":"jsonpath","expr":"$.warnings"},"predicate":{"type":"exist"}},{"query":{"type":"jsonpath","expr":"$.errors[0]"},"predicate":{"type":"exist"}},{"query":{"type":"jsonpath","expr":"$.errors[0].id"},"predicate":{"type":"equal","value":"error1"}},{"query":{"type":"jsonpath","expr":"$.errors[0]['id']"},"predicate":{"type":"equal","value":"error1"}},{"query":{"type":"jsonpath","expr":"$.duration"},"predicate":{"type":"equal","value":1.5}},{"query":{"type":"jsonpath","expr":"$.duration"},"predicate":{"type":"less-than-or-equal","value":"2.0"}},{"query":{"type":"jsonpath","expr":"$.duration"},"predicate":{"type":"greater-than","value":"2"}},{"query":{"type":"jsonpath","expr":"$.nullable"},"predicate":{"type":"equal","value":null}}],"body":{"type":"json","value":{"success":false,"errors":[{"id":"error1"},{"id":"error2"}],"warnings":[],"duration":1.5,"tags":["test"],"nullable":null}}}},{"request":{"method":"GET","url":"http://localhost:8000/assert-json/index"},"response":{"version":"HTTP/1.0","status":200,"captures":[{"name":"index","query":{"type":"body"}}]}},{"request":{"method":"GET","url":"http://localhost:8000/assert-json"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"jsonpath","expr":"$.errors[{{index}}].id"},"predicate":{"type":"equal","value":"error2"}},{"query":{"type":"jsonpath","expr":"$.tags"},"predicate":{"type":"include","value":"test"}},{"query":{"type":"jsonpath","expr":"$.tags"},"predicate":{"not":true,"type":"include","value":"prod"}},{"query":{"type":"jsonpath","expr":"$.tags"},"predicate":{"not":true,"type":"include","value":null}}]}}]}
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/assert-json"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"jsonpath","expr":"$.success"},"predicate":{"type":"equal","value":false}},{"query":{"type":"jsonpath","expr":"$.success"},"predicate":{"not":true,"type":"equal","value":null}},{"query":{"type":"jsonpath","expr":"$.success"},"predicate":{"type":"exist"}},{"query":{"type":"jsonpath","expr":"$.errors"},"predicate":{"type":"count","value":2}},{"query":{"type":"jsonpath","expr":"$.warnings"},"predicate":{"type":"count","value":0}},{"query":{"type":"jsonpath","expr":"$.toto"},"predicate":{"not":true,"type":"exist"}},{"query":{"type":"jsonpath","expr":"$.warnings"},"predicate":{"type":"exist"}},{"query":{"type":"jsonpath","expr":"$.warnings"},"predicate":{"type":"exist"}},{"query":{"type":"jsonpath","expr":"$.errors[0]"},"predicate":{"type":"exist"}},{"query":{"type":"jsonpath","expr":"$.errors[0].id"},"predicate":{"type":"equal","value":"error1"}},{"query":{"type":"jsonpath","expr":"$.errors[0]['id']"},"predicate":{"type":"equal","value":"error1"}},{"query":{"type":"jsonpath","expr":"$.duration"},"predicate":{"type":"equal","value":1.5}},{"query":{"type":"jsonpath","expr":"$.duration"},"predicate":{"type":"less-than-or-equal","value":"2.0"}},{"query":{"type":"jsonpath","expr":"$.duration"},"predicate":{"type":"greater-than","value":"2"}},{"query":{"type":"jsonpath","expr":"$.nullable"},"predicate":{"type":"equal","value":null}}],"body":{"type":"json","value":{"success":false,"errors":[{"id":"error1"},{"id":"error2"}],"warnings":[],"duration":1.5,"tags":["test"],"nullable":null}}}},{"request":{"method":"GET","url":"http://localhost:8000/assert-json/index"},"response":{"version":"HTTP/1.0","status":200,"captures":[{"name":"index","query":{"type":"body"}}]}},{"request":{"method":"GET","url":"http://localhost:8000/assert-json"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"jsonpath","expr":"$.errors[{{index}}].id"},"predicate":{"type":"equal","value":"error2"}},{"query":{"type":"jsonpath","expr":"$.tags"},"predicate":{"type":"include","value":"test"}},{"query":{"type":"jsonpath","expr":"$.tags"},"predicate":{"not":true,"type":"include","value":"prod"}},{"query":{"type":"jsonpath","expr":"$.tags"},"predicate":{"not":true,"type":"include","value":null}}]}},{"request":{"method":"GET","url":"http://localhost:8000/assert-json/list"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"jsonpath","expr":"$"},"predicate":{"type":"count","value":2}},{"query":{"type":"jsonpath","expr":"$.[0].name"},"predicate":{"type":"equal","value":"Bob"}},{"query":{"type":"jsonpath","expr":"$[0].name"},"predicate":{"type":"equal","value":"Bob"}}]}}]}
8 changes: 0 additions & 8 deletions integration/tests/assert_json.out

This file was deleted.

10 changes: 9 additions & 1 deletion integration/tests/assert_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ def assert_json():

@app.route("/assert-json/index")
def assert_json_index():
return "1"
return "1"

@app.route("/assert-json/list")
def assert_json_list():
return Response('''[
{ "id": 1, "name": "Bob"},
{ "id": 2, "name": "Bill"}
]''', mimetype='application/json')

Loading

0 comments on commit 6d5239a

Please sign in to comment.