Skip to content

Commit

Permalink
Add integ test for jsonpath filter
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricereix committed Dec 15, 2023
1 parent 80159a8 commit a4ea22f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
53 changes: 53 additions & 0 deletions integration/hurl/tests_ok/assert_json.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,59 @@ jsonpath "$.fruit.[?(@.US == 100)]" count == 0 # To be clarified with spec: th
]
}

GET http://localhost:8000/assert-json/filter-by-name
HTTP 200
[Asserts]

jsonpath "$..*[?(@.name)]" count == 5
jsonpath "$..*[?(@.name=='car')].id" nth 0 == 1
jsonpath "$..*[?(@.name=='wheel')].id" nth 0 == 4

jsonpath "$..items[?(@.name)]" count == 5
jsonpath "$..items[?(@.name=='car')].id" nth 0 == 1
jsonpath "$..items[?(@.name=='wheel')].id" nth 0 == 4

jsonpath "$.main.items[?(@.name)]" count == 3
jsonpath "$.main.items[?(@.name=='car')].id" nth 0 == 1
jsonpath "$.main.items[?(@.name=='wheel')].id" isEmpty

jsonpath "$.main..items[?(@.name)]" count == 4
jsonpath "$.main..items[?(@.name=='car')].id" nth 0 == 1
jsonpath "$.main..items[?(@.name=='wheel')].id" nth 0 == 4

{
"main": {
"items": [
{
"id": 1,
"name": "car"
},
{
"id": 2,
"name": "bike",
"items": [
{
"id": 4,
"name": "wheel"
}
]
},
{
"id": 3,
"name": "plane"
}
]
},
"more": {
"items": [
{
"id": 5,
"name": "scooter"
}
]
}
}

GET http://localhost:8000/assert-json/big-number
HTTP 200
[Asserts]
Expand Down
37 changes: 37 additions & 0 deletions integration/hurl/tests_ok/assert_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,43 @@ def assert_json_filter():
mimetype="application/json",
)

@app.route("/assert-json/filter-by-name")
def assert_json_filter_ny_name():
return Response(
"""{
"main": {
"items": [
{
"id": 1,
"name": "car"
},
{
"id": 2,
"name": "bike",
"items": [
{
"id": 4,
"name": "wheel"
}
]
},
{
"id": 3,
"name": "plane"
}
]
},
"more": {
"items": [
{
"id": 5,
"name": "scooter"
}
]
}
}""",
mimetype="application/json",
)

@app.route("/assert-json/big-number")
def assert_json_big_number():
Expand Down

0 comments on commit a4ea22f

Please sign in to comment.