hurl/integration/tests_ok/post_json.py

90 lines
2.0 KiB
Python
Raw Normal View History

2020-08-27 10:07:46 +03:00
from flask import request
from app import app
2020-08-27 10:07:46 +03:00
@app.route("/post-json", methods=["POST"])
2020-08-27 10:07:46 +03:00
def post_json():
assert request.headers["Content-Type"] == "application/json"
2020-08-27 10:07:46 +03:00
s = request.data.decode("utf-8")
print(s)
assert (
s
== """{
2020-08-27 10:07:46 +03:00
"name": "Bob",
2022-04-11 11:53:52 +03:00
"password": "&secret\\\\'<>",
"age": 30,
2021-07-25 09:19:56 +03:00
"strict": true,
"spacing": "\\n",
2022-03-09 11:51:17 +03:00
"g_clef": "\\uD834\\uDD1E",
2022-06-21 10:19:13 +03:00
"items": [true, \"true\", 1],
"variable": "\\\\"
}"""
)
return ""
2020-08-27 10:07:46 +03:00
@app.route("/post-json-array", methods=["POST"])
2020-08-27 10:07:46 +03:00
def post_json_array():
assert request.headers["Content-Type"] == "application/json"
2020-08-27 10:07:46 +03:00
s = request.data.decode("utf-8")
assert s == "[1,2,3]"
return ""
2020-08-27 10:07:46 +03:00
@app.route("/post-json-string", methods=["POST"])
2020-08-27 10:07:46 +03:00
def post_json_string():
assert request.headers["Content-Type"] == "application/json"
2020-08-27 10:07:46 +03:00
s = request.data.decode("utf-8")
assert s == '"Hello"'
return ""
2020-08-27 10:07:46 +03:00
@app.route("/post-json-number", methods=["POST"])
2020-08-27 10:07:46 +03:00
def post_json_number():
assert request.headers["Content-Type"] == "application/json"
2020-08-27 10:07:46 +03:00
s = request.data.decode("utf-8")
assert s == "100"
return ""
2020-08-27 10:07:46 +03:00
@app.route("/post-json-boolean", methods=["POST"])
2020-08-27 10:07:46 +03:00
def post_json_boolean():
assert request.headers["Content-Type"] == "application/json"
2020-08-27 10:07:46 +03:00
s = request.data.decode("utf-8")
assert s == "true"
return ""
2020-08-27 10:07:46 +03:00
@app.route("/post-json-numbers", methods=["POST"])
2020-08-27 10:07:46 +03:00
def post_json_numbers():
assert request.headers["Content-Type"] == "application/json"
2020-08-27 10:07:46 +03:00
s = request.data.decode("utf-8")
assert (
s
== """{
2020-08-27 10:07:46 +03:00
"natural": 100,
"negative": -1,
"float": "3.333333333333333",
"exponent": 100e100
}"""
)
return ""
2020-08-27 10:07:46 +03:00
@app.route("/get-name")
2020-08-27 10:07:46 +03:00
def get_name():
return "Bob"
2020-08-27 10:07:46 +03:00
@app.route("/check_name", methods=["POST"])
2021-07-25 09:19:56 +03:00
def check_name():
assert request.headers["Content-Type"] == "application/json"
2021-07-25 09:19:56 +03:00
s = request.data.decode("utf-8")
assert (
s
== """{
2021-07-25 09:19:56 +03:00
"name": "Bob"
}"""
)
return ""