2020-08-27 10:07:46 +03:00
|
|
|
from flask import request
|
2022-02-14 11:13:33 +03:00
|
|
|
from app import app
|
2020-08-27 10:07:46 +03:00
|
|
|
|
|
|
|
|
2022-02-05 08:56:33 +03:00
|
|
|
@app.route("/post-json", methods=["POST"])
|
2020-08-27 10:07:46 +03:00
|
|
|
def post_json():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert request.headers["Content-Type"] == "application/json"
|
2020-08-27 10:07:46 +03:00
|
|
|
s = request.data.decode("utf-8")
|
2021-01-09 12:28:57 +03:00
|
|
|
print(s)
|
2022-02-05 08:56:33 +03:00
|
|
|
assert (
|
|
|
|
s
|
|
|
|
== """{
|
2020-08-27 10:07:46 +03:00
|
|
|
"name": "Bob",
|
2022-04-11 11:53:52 +03:00
|
|
|
"password": "&secret\\\\'<>",
|
2021-01-09 12:28:57 +03:00
|
|
|
"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": "\\\\"
|
2022-02-05 08:56:33 +03:00
|
|
|
}"""
|
|
|
|
)
|
|
|
|
return ""
|
2020-08-27 10:07:46 +03:00
|
|
|
|
|
|
|
|
2022-02-05 08:56:33 +03:00
|
|
|
@app.route("/post-json-array", methods=["POST"])
|
2020-08-27 10:07:46 +03:00
|
|
|
def post_json_array():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert request.headers["Content-Type"] == "application/json"
|
2020-08-27 10:07:46 +03:00
|
|
|
s = request.data.decode("utf-8")
|
2022-02-05 08:56:33 +03:00
|
|
|
assert s == "[1,2,3]"
|
|
|
|
return ""
|
2020-08-27 10:07:46 +03:00
|
|
|
|
|
|
|
|
2022-02-05 08:56:33 +03:00
|
|
|
@app.route("/post-json-string", methods=["POST"])
|
2020-08-27 10:07:46 +03:00
|
|
|
def post_json_string():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert request.headers["Content-Type"] == "application/json"
|
2020-08-27 10:07:46 +03:00
|
|
|
s = request.data.decode("utf-8")
|
|
|
|
assert s == '"Hello"'
|
2022-02-05 08:56:33 +03:00
|
|
|
return ""
|
2020-08-27 10:07:46 +03:00
|
|
|
|
|
|
|
|
2022-02-05 08:56:33 +03:00
|
|
|
@app.route("/post-json-number", methods=["POST"])
|
2020-08-27 10:07:46 +03:00
|
|
|
def post_json_number():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert request.headers["Content-Type"] == "application/json"
|
2020-08-27 10:07:46 +03:00
|
|
|
s = request.data.decode("utf-8")
|
2022-02-05 08:56:33 +03:00
|
|
|
assert s == "100"
|
|
|
|
return ""
|
2020-08-27 10:07:46 +03:00
|
|
|
|
|
|
|
|
2022-02-05 08:56:33 +03:00
|
|
|
@app.route("/post-json-boolean", methods=["POST"])
|
2020-08-27 10:07:46 +03:00
|
|
|
def post_json_boolean():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert request.headers["Content-Type"] == "application/json"
|
2020-08-27 10:07:46 +03:00
|
|
|
s = request.data.decode("utf-8")
|
2022-02-05 08:56:33 +03:00
|
|
|
assert s == "true"
|
|
|
|
return ""
|
2020-08-27 10:07:46 +03:00
|
|
|
|
2022-02-05 08:56:33 +03:00
|
|
|
|
|
|
|
@app.route("/post-json-numbers", methods=["POST"])
|
2020-08-27 10:07:46 +03:00
|
|
|
def post_json_numbers():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert request.headers["Content-Type"] == "application/json"
|
2020-08-27 10:07:46 +03:00
|
|
|
s = request.data.decode("utf-8")
|
2022-02-05 08:56:33 +03:00
|
|
|
assert (
|
|
|
|
s
|
|
|
|
== """{
|
2020-08-27 10:07:46 +03:00
|
|
|
"natural": 100,
|
|
|
|
"negative": -1,
|
|
|
|
"float": "3.333333333333333",
|
|
|
|
"exponent": 100e100
|
2022-02-05 08:56:33 +03:00
|
|
|
}"""
|
|
|
|
)
|
|
|
|
return ""
|
|
|
|
|
2020-08-27 10:07:46 +03:00
|
|
|
|
2022-02-05 08:56:33 +03:00
|
|
|
@app.route("/get-name")
|
2020-08-27 10:07:46 +03:00
|
|
|
def get_name():
|
2022-02-05 08:56:33 +03:00
|
|
|
return "Bob"
|
|
|
|
|
2020-08-27 10:07:46 +03:00
|
|
|
|
2022-02-05 08:56:33 +03:00
|
|
|
@app.route("/check_name", methods=["POST"])
|
2021-07-25 09:19:56 +03:00
|
|
|
def check_name():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert request.headers["Content-Type"] == "application/json"
|
2021-07-25 09:19:56 +03:00
|
|
|
s = request.data.decode("utf-8")
|
2022-02-05 08:56:33 +03:00
|
|
|
assert (
|
|
|
|
s
|
|
|
|
== """{
|
2021-07-25 09:19:56 +03:00
|
|
|
"name": "Bob"
|
2022-02-05 08:56:33 +03:00
|
|
|
}"""
|
|
|
|
)
|
|
|
|
return ""
|