hurl/integration/tests/post_json.py

75 lines
1.8 KiB
Python
Raw Normal View History

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