mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-22 15:42:20 +03:00
Format python files with black formater
This commit is contained in:
parent
b3246fef1b
commit
5e9a94a430
@ -2,6 +2,7 @@
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def check(expected, actual):
|
||||
expected_test = json.loads(expected)
|
||||
actual_test = json.loads(actual)
|
||||
@ -9,68 +10,67 @@ def check(expected, actual):
|
||||
|
||||
|
||||
def check_output(expected_test, actual_test):
|
||||
expected_entries = expected_test['entries']
|
||||
actual_entries = actual_test['entries']
|
||||
expected_entries = expected_test["entries"]
|
||||
actual_entries = actual_test["entries"]
|
||||
if len(expected_entries) != len(actual_entries):
|
||||
print('expected entries: %d' % len(expected_entries))
|
||||
print('actual entries: %d' % len(actual_entries))
|
||||
print("expected entries: %d" % len(expected_entries))
|
||||
print("actual entries: %d" % len(actual_entries))
|
||||
sys.exit(1)
|
||||
for i in range(len(expected_entries)):
|
||||
check_entry(i, expected_entries[i], actual_entries[i])
|
||||
|
||||
|
||||
def check_entry(entry_index, expected_entry, actual_entry):
|
||||
check_request(entry_index, expected_entry['request'], actual_entry['request'])
|
||||
check_response(entry_index, expected_entry['response'], actual_entry['response'])
|
||||
if expected_entry.get('asserts') is not None:
|
||||
check_asserts(entry_index, expected_entry['asserts'], actual_entry['asserts'])
|
||||
check_request(entry_index, expected_entry["request"], actual_entry["request"])
|
||||
check_response(entry_index, expected_entry["response"], actual_entry["response"])
|
||||
if expected_entry.get("asserts") is not None:
|
||||
check_asserts(entry_index, expected_entry["asserts"], actual_entry["asserts"])
|
||||
|
||||
|
||||
def check_request(entry_index, expected_request, actual_request):
|
||||
check_method(entry_index, expected_request['method'], actual_request['method'])
|
||||
check_url(entry_index, expected_request['url'], actual_request['url'])
|
||||
check_method(entry_index, expected_request["method"], actual_request["method"])
|
||||
check_url(entry_index, expected_request["url"], actual_request["url"])
|
||||
|
||||
|
||||
def check_response(entry_index, expected_response, actual_response):
|
||||
check_status(entry_index, expected_response['status'], actual_response['status'])
|
||||
|
||||
check_status(entry_index, expected_response["status"], actual_response["status"])
|
||||
|
||||
|
||||
def check_method(entry_index, expected, actual):
|
||||
if expected != actual:
|
||||
print('Invalid entry %d' % entry_index)
|
||||
print('expected method: %s' % expected)
|
||||
print('actual method : %s' % actual)
|
||||
print("Invalid entry %d" % entry_index)
|
||||
print("expected method: %s" % expected)
|
||||
print("actual method : %s" % actual)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_url(entry_index, expected, actual):
|
||||
if expected != actual:
|
||||
print('Invalid entry %d' % entry_index)
|
||||
print('expected url: %s' % expected)
|
||||
print('actual url : %s' % actual)
|
||||
print("Invalid entry %d" % entry_index)
|
||||
print("expected url: %s" % expected)
|
||||
print("actual url : %s" % actual)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_status(entry_index, expected, actual):
|
||||
if expected != actual:
|
||||
print('Invalid entry %d' % entry_index)
|
||||
print('expected status: %s' % expected)
|
||||
print('actual status : %s' % actual)
|
||||
print("Invalid entry %d" % entry_index)
|
||||
print("expected status: %s" % expected)
|
||||
print("actual status : %s" % actual)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_asserts(entry_index, expected, actual):
|
||||
if expected != actual:
|
||||
print('Invalid entry %d' % entry_index)
|
||||
print('expected asserts:\n%s' % json.dumps(expected, indent=2))
|
||||
print('actual asserts:\n%s' % json.dumps(actual, indent=2))
|
||||
print("Invalid entry %d" % entry_index)
|
||||
print("expected asserts:\n%s" % json.dumps(expected, indent=2))
|
||||
print("actual asserts:\n%s" % json.dumps(actual, indent=2))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 3:
|
||||
print('usage: check_output.py expected_file actual_file')
|
||||
print("usage: check_output.py expected_file actual_file")
|
||||
sys.exit(1)
|
||||
expected_file = sys.argv[1]
|
||||
actual_file = sys.argv[2]
|
||||
@ -79,9 +79,5 @@ def main():
|
||||
check_file(expected, actual)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
import glob
|
||||
import glob
|
||||
import test_echo
|
||||
import test_lint
|
||||
import test_format
|
||||
@ -7,23 +7,25 @@ import test_hurl
|
||||
|
||||
|
||||
def get_files(glob_expr):
|
||||
return sorted([f.replace('\\', '/') for f in glob.glob(glob_expr)])
|
||||
return sorted([f.replace("\\", "/") for f in glob.glob(glob_expr)])
|
||||
|
||||
|
||||
def main():
|
||||
# Static run (without server)
|
||||
[test_echo.test(f) for f in get_files('tests/*.hurl') + get_files('tests_error_lint/*.hurl')]
|
||||
[test_format.test('json', f) for f in get_files('tests/*.hurl')]
|
||||
[test_format.test('html', f) for f in get_files('tests/*.hurl')]
|
||||
[test_lint.test(f) for f in get_files('tests_error_lint/*.hurl')]
|
||||
[test_hurl.test(f) for f in get_files('tests_error_parser/*.hurl')]
|
||||
[
|
||||
test_echo.test(f)
|
||||
for f in get_files("tests/*.hurl") + get_files("tests_error_lint/*.hurl")
|
||||
]
|
||||
[test_format.test("json", f) for f in get_files("tests/*.hurl")]
|
||||
[test_format.test("html", f) for f in get_files("tests/*.hurl")]
|
||||
[test_lint.test(f) for f in get_files("tests_error_lint/*.hurl")]
|
||||
[test_hurl.test(f) for f in get_files("tests_error_parser/*.hurl")]
|
||||
|
||||
# Dynamic run (with server)
|
||||
[test_hurl.test(f) for f in get_files('tests/*.hurl') + get_files('ssl/*.hurl')]
|
||||
[test_hurl.test(f) for f in get_files("tests/*.hurl") + get_files("ssl/*.hurl")]
|
||||
|
||||
print('test integration ok!')
|
||||
print("test integration ok!")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from tests import app
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=8000)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=8000)
|
||||
|
@ -4,11 +4,12 @@ import os
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route("/hello")
|
||||
def hello():
|
||||
return "Hello World!"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ssl_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
app.run(port=8001, ssl_context=(ssl_dir + '/cert.pem', ssl_dir + '/key.pem'))
|
||||
|
||||
app.run(port=8001, ssl_context=(ssl_dir + "/cert.pem", ssl_dir + "/key.pem"))
|
||||
|
@ -6,27 +6,29 @@ import sys
|
||||
import subprocess
|
||||
import codecs
|
||||
|
||||
|
||||
def decode_string(encoded):
|
||||
if encoded.startswith(codecs.BOM_UTF8):
|
||||
return encoded.decode('utf-8-sig')
|
||||
return encoded.decode("utf-8-sig")
|
||||
elif encoded.startswith(codecs.BOM_UTF16):
|
||||
encoded = encoded[len(codecs.BOM_UTF16):]
|
||||
return encoded.decode('utf-16')
|
||||
encoded = encoded[len(codecs.BOM_UTF16) :]
|
||||
return encoded.decode("utf-16")
|
||||
else:
|
||||
return encoded.decode()
|
||||
|
||||
|
||||
def test(hurl_file):
|
||||
cmd = ['hurlfmt', '--no-format', hurl_file]
|
||||
print(' '.join(cmd))
|
||||
cmd = ["hurlfmt", "--no-format", hurl_file]
|
||||
print(" ".join(cmd))
|
||||
result = subprocess.run(cmd, stdout=subprocess.PIPE)
|
||||
expected = codecs.open(hurl_file, encoding='utf-8-sig').read() # Input file can be saved with a BOM
|
||||
expected = codecs.open(
|
||||
hurl_file, encoding="utf-8-sig"
|
||||
).read() # Input file can be saved with a BOM
|
||||
actual = decode_string(result.stdout)
|
||||
if actual != expected:
|
||||
print('>>> error in stdout')
|
||||
print(f'actual: <{actual}>\nexpected: <{expected}>')
|
||||
print(">>> error in stdout")
|
||||
print(f"actual: <{actual}>\nexpected: <{expected}>")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
@ -34,6 +36,5 @@ def main():
|
||||
test(hurl_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
@ -7,41 +7,41 @@ import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
def decode_string(encoded):
|
||||
if encoded.startswith(codecs.BOM_UTF8):
|
||||
return encoded.decode('utf-8-sig')
|
||||
return encoded.decode("utf-8-sig")
|
||||
elif encoded.startswith(codecs.BOM_UTF16):
|
||||
encoded = encoded[len(codecs.BOM_UTF16):]
|
||||
return encoded.decode('utf-16')
|
||||
encoded = encoded[len(codecs.BOM_UTF16) :]
|
||||
return encoded.decode("utf-16")
|
||||
else:
|
||||
return encoded.decode()
|
||||
|
||||
|
||||
def test(format_type, hurl_file):
|
||||
output_file = hurl_file.replace('.hurl','.' + format_type)
|
||||
output_file = hurl_file.replace(".hurl", "." + format_type)
|
||||
if not os.path.exists(output_file):
|
||||
return
|
||||
cmd = ['hurlfmt', '--format', format_type, hurl_file]
|
||||
print(' '.join(cmd))
|
||||
cmd = ["hurlfmt", "--format", format_type, hurl_file]
|
||||
print(" ".join(cmd))
|
||||
result = subprocess.run(cmd, stdout=subprocess.PIPE)
|
||||
expected = open(output_file, encoding='utf-8').read().strip()
|
||||
expected = open(output_file, encoding="utf-8").read().strip()
|
||||
actual = decode_string(result.stdout)
|
||||
if actual != expected:
|
||||
print('>>> error in stdout')
|
||||
print(f'actual: <{actual}>\nexpected: <{expected}>')
|
||||
print(">>> error in stdout")
|
||||
print(f"actual: <{actual}>\nexpected: <{expected}>")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print('usage: test_format.py json|html HURL_FILE..')
|
||||
print("usage: test_format.py json|html HURL_FILE..")
|
||||
sys.exit(1)
|
||||
format_type = sys.argv[1]
|
||||
format_type = sys.argv[1]
|
||||
|
||||
for hurl_file in sys.argv[2:]:
|
||||
test(format_type, hurl_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
@ -5,17 +5,20 @@ from bs4 import BeautifulSoup
|
||||
import os
|
||||
import codecs
|
||||
|
||||
|
||||
def test(html_file):
|
||||
print(html_file)
|
||||
actual = extract_hurl_content(html_file)
|
||||
|
||||
hurl_file = os.path.splitext(html_file)[0] + '.hurl'
|
||||
hurl_file = os.path.splitext(html_file)[0] + ".hurl"
|
||||
if not os.path.isfile(hurl_file):
|
||||
return
|
||||
expected = codecs.open(hurl_file, encoding='utf-8-sig').read() # Input file can be saved with a BOM
|
||||
expected = codecs.open(
|
||||
hurl_file, encoding="utf-8-sig"
|
||||
).read() # Input file can be saved with a BOM
|
||||
if actual != expected:
|
||||
print('>>> error in html file')
|
||||
print(f'actual: <{actual}>\nexpected: <{expected}>')
|
||||
print(">>> error in html file")
|
||||
print(f"actual: <{actual}>\nexpected: <{expected}>")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@ -25,10 +28,10 @@ def extract_hurl_content(hurl_file):
|
||||
|
||||
|
||||
def main():
|
||||
print('** test html output')
|
||||
print("** test html output")
|
||||
for html_file in sys.argv[1:]:
|
||||
test(html_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -12,85 +12,87 @@ import tempfile
|
||||
|
||||
def decode_string(encoded):
|
||||
if encoded.startswith(codecs.BOM_UTF8):
|
||||
return encoded.decode('utf-8-sig')
|
||||
return encoded.decode("utf-8-sig")
|
||||
elif encoded.startswith(codecs.BOM_UTF16):
|
||||
encoded = encoded[len(codecs.BOM_UTF16):]
|
||||
return encoded.decode('utf-16')
|
||||
encoded = encoded[len(codecs.BOM_UTF16) :]
|
||||
return encoded.decode("utf-16")
|
||||
else:
|
||||
return encoded.decode()
|
||||
|
||||
|
||||
# return linux, osx or windows
|
||||
def get_os():
|
||||
if platform.system() == 'Linux':
|
||||
return 'linux'
|
||||
elif platform.system() == 'Darwin':
|
||||
return 'osx'
|
||||
elif platform.system() == 'Windows':
|
||||
return 'windows'
|
||||
if platform.system() == "Linux":
|
||||
return "linux"
|
||||
elif platform.system() == "Darwin":
|
||||
return "osx"
|
||||
elif platform.system() == "Windows":
|
||||
return "windows"
|
||||
else:
|
||||
raise Error('Invalid Platform ' + platform.system())
|
||||
raise Error("Invalid Platform " + platform.system())
|
||||
|
||||
|
||||
def test(hurl_file):
|
||||
|
||||
options_file = hurl_file.replace('.hurl', '.options')
|
||||
options_file = hurl_file.replace(".hurl", ".options")
|
||||
|
||||
# For .curl file, we can have specific os expected file in order to test
|
||||
# os differences like included path (/ vs \ path components separator)
|
||||
os_curl_file = hurl_file.replace('.hurl', '.' + get_os() + '.curl')
|
||||
os_curl_file = hurl_file.replace(".hurl", "." + get_os() + ".curl")
|
||||
if os.path.exists(os_curl_file):
|
||||
curl_file = os_curl_file
|
||||
else:
|
||||
curl_file = hurl_file.replace('.hurl', '.curl')
|
||||
curl_file = hurl_file.replace(".hurl", ".curl")
|
||||
|
||||
json_output_file = hurl_file.replace('.hurl', '.output.json')
|
||||
profile_file = hurl_file.replace('.hurl', '.profile')
|
||||
json_output_file = hurl_file.replace(".hurl", ".output.json")
|
||||
profile_file = hurl_file.replace(".hurl", ".profile")
|
||||
|
||||
options = []
|
||||
if os.path.exists(options_file):
|
||||
options = open(options_file).read().strip().split('\n')
|
||||
options = open(options_file).read().strip().split("\n")
|
||||
if os.path.exists(curl_file):
|
||||
options.append('--verbose')
|
||||
options.append("--verbose")
|
||||
|
||||
if os.path.exists(json_output_file):
|
||||
options.append('--json')
|
||||
options.append("--json")
|
||||
|
||||
env = os.environ.copy()
|
||||
if os.path.exists(profile_file):
|
||||
for line in open(profile_file).readlines():
|
||||
line = line.strip()
|
||||
if line == '':
|
||||
if line == "":
|
||||
continue
|
||||
index = line.index('=')
|
||||
index = line.index("=")
|
||||
name = line[:index]
|
||||
value = line[(index+1):]
|
||||
value = line[(index + 1) :]
|
||||
env[name] = value
|
||||
|
||||
cmd = ['hurl', hurl_file] + options
|
||||
print(' '.join(cmd))
|
||||
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,env=env)
|
||||
cmd = ["hurl", hurl_file] + options
|
||||
print(" ".join(cmd))
|
||||
result = subprocess.run(
|
||||
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env
|
||||
)
|
||||
|
||||
# exit code
|
||||
f = hurl_file.replace('.hurl','.exit')
|
||||
# exit code
|
||||
f = hurl_file.replace(".hurl", ".exit")
|
||||
expected = int(open(f).read().strip())
|
||||
if result.returncode != expected:
|
||||
print('>>> error in return code')
|
||||
print(f'expected: {expected} actual:{result.returncode}')
|
||||
print(">>> error in return code")
|
||||
print(f"expected: {expected} actual:{result.returncode}")
|
||||
stderr = decode_string(result.stderr).strip()
|
||||
if stderr != '':
|
||||
if stderr != "":
|
||||
print(stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# stdout
|
||||
f = hurl_file.replace('.hurl','.out')
|
||||
f = hurl_file.replace(".hurl", ".out")
|
||||
if os.path.exists(f):
|
||||
expected = open(f, 'rb').read()
|
||||
actual = result.stdout
|
||||
if expected != actual:
|
||||
print('>>> error in stdout')
|
||||
print(f'actual: <{actual}>\nexpected: <{expected}>')
|
||||
sys.exit(1)
|
||||
expected = open(f, "rb").read()
|
||||
actual = result.stdout
|
||||
if expected != actual:
|
||||
print(">>> error in stdout")
|
||||
print(f"actual: <{actual}>\nexpected: <{expected}>")
|
||||
sys.exit(1)
|
||||
|
||||
# stdout (json)
|
||||
if os.path.exists(json_output_file):
|
||||
@ -99,47 +101,49 @@ def test(hurl_file):
|
||||
check_json_output.check(expected, actual)
|
||||
|
||||
# stderr
|
||||
f = hurl_file.replace('.hurl', '.' + get_os() + '.err')
|
||||
f = hurl_file.replace(".hurl", "." + get_os() + ".err")
|
||||
if os.path.exists(f):
|
||||
expected = open(f).read().strip()
|
||||
actual = decode_string(result.stderr).strip()
|
||||
if expected != actual:
|
||||
print('>>> error in stderr')
|
||||
print(f'actual: <{actual}>\nexpected: <{expected}>')
|
||||
print(">>> error in stderr")
|
||||
print(f"actual: <{actual}>\nexpected: <{expected}>")
|
||||
sys.exit(1)
|
||||
else:
|
||||
f = hurl_file.replace('.hurl', '.err')
|
||||
f = hurl_file.replace(".hurl", ".err")
|
||||
if os.path.exists(f):
|
||||
expected = open(f).read().strip()
|
||||
actual = decode_string(result.stderr).strip()
|
||||
if expected != actual:
|
||||
print('>>> error in stderr')
|
||||
print(f'actual: <{actual}>\nexpected: <{expected}>')
|
||||
print(">>> error in stderr")
|
||||
print(f"actual: <{actual}>\nexpected: <{expected}>")
|
||||
sys.exit(1)
|
||||
|
||||
# curl output
|
||||
if os.path.exists(curl_file):
|
||||
expected_commands = []
|
||||
for line in open(curl_file, 'r').readlines():
|
||||
line = line.strip()
|
||||
if line == "" or line.startswith("#"):
|
||||
continue
|
||||
expected_commands.append(line)
|
||||
for line in open(curl_file, "r").readlines():
|
||||
line = line.strip()
|
||||
if line == "" or line.startswith("#"):
|
||||
continue
|
||||
expected_commands.append(line)
|
||||
|
||||
actual = decode_string(result.stderr).strip()
|
||||
actual_commands= [line[2:] for line in actual.split('\n') if line.startswith('* curl')]
|
||||
actual_commands = [
|
||||
line[2:] for line in actual.split("\n") if line.startswith("* curl")
|
||||
]
|
||||
|
||||
if len(actual_commands) != len(expected_commands):
|
||||
print('Assert error at %s' % (f))
|
||||
print('expected: %d commands' % len(expected_commands))
|
||||
print('actual: %d commands' % len(actual_commands))
|
||||
sys.exit(1)
|
||||
print("Assert error at %s" % (f))
|
||||
print("expected: %d commands" % len(expected_commands))
|
||||
print("actual: %d commands" % len(actual_commands))
|
||||
sys.exit(1)
|
||||
|
||||
for i in range(len(expected_commands)):
|
||||
if actual_commands[i] != expected_commands[i]:
|
||||
print('Assert error at %s:%i' % (curl_file, i+1))
|
||||
print('expected: %s' % expected_commands[i])
|
||||
print('actual: %s' % actual_commands[i])
|
||||
print("Assert error at %s:%i" % (curl_file, i + 1))
|
||||
print("expected: %s" % expected_commands[i])
|
||||
print("actual: %s" % actual_commands[i])
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@ -148,9 +152,5 @@ def main():
|
||||
test(hurl_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -5,41 +5,42 @@ import codecs
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
def decode_string(encoded):
|
||||
if encoded.startswith(codecs.BOM_UTF8):
|
||||
return encoded.decode('utf-8-sig')
|
||||
return encoded.decode("utf-8-sig")
|
||||
elif encoded.startswith(codecs.BOM_UTF16):
|
||||
encoded = encoded[len(codecs.BOM_UTF16):]
|
||||
return encoded.decode('utf-16')
|
||||
encoded = encoded[len(codecs.BOM_UTF16) :]
|
||||
return encoded.decode("utf-16")
|
||||
else:
|
||||
return encoded.decode()
|
||||
|
||||
|
||||
def test(hurl_file):
|
||||
cmd = ['hurlfmt', '--check', hurl_file]
|
||||
print(' '.join(cmd))
|
||||
cmd = ["hurlfmt", "--check", hurl_file]
|
||||
print(" ".join(cmd))
|
||||
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if result.returncode != 1:
|
||||
print(f'return code => expected: 1 actual {result.returncode}')
|
||||
print(f"return code => expected: 1 actual {result.returncode}")
|
||||
sys.exit(1)
|
||||
|
||||
err_file = hurl_file.replace('.hurl','.err')
|
||||
err_file = hurl_file.replace(".hurl", ".err")
|
||||
expected = open(err_file).read().strip()
|
||||
actual = decode_string(result.stderr).strip()
|
||||
if actual != expected:
|
||||
print('>>> error in stderr')
|
||||
print(f'actual: <{actual}>\nexpected: <{expected}>')
|
||||
print(">>> error in stderr")
|
||||
print(f"actual: <{actual}>\nexpected: <{expected}>")
|
||||
sys.exit(1)
|
||||
|
||||
cmd = ['hurlfmt', hurl_file]
|
||||
print(' '.join(cmd))
|
||||
cmd = ["hurlfmt", hurl_file]
|
||||
print(" ".join(cmd))
|
||||
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
err_file = hurl_file.replace('.hurl','.hurl.lint')
|
||||
err_file = hurl_file.replace(".hurl", ".hurl.lint")
|
||||
expected = open(err_file).read().strip()
|
||||
actual = decode_string(result.stdout).strip()
|
||||
if actual != expected:
|
||||
print('>>> error in stdout')
|
||||
print(f'actual: <{actual}>\nexpected: <{expected}>')
|
||||
print(">>> error in stdout")
|
||||
print(f"actual: <{actual}>\nexpected: <{expected}>")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@ -48,8 +49,5 @@ def main():
|
||||
test(hurl_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
@ -6,18 +6,18 @@ import os
|
||||
app = Flask(__name__)
|
||||
|
||||
current_dir = os.path.basename(os.path.dirname(__file__))
|
||||
for python_file in glob.glob(current_dir + '/*.py'):
|
||||
if python_file.endswith('__init__.py'):
|
||||
for python_file in glob.glob(current_dir + "/*.py"):
|
||||
if python_file.endswith("__init__.py"):
|
||||
continue
|
||||
module_name = python_file.split('.')[0].replace(os.path.sep, '.')
|
||||
print('loading %s' % module_name)
|
||||
module_name = python_file.split(".")[0].replace(os.path.sep, ".")
|
||||
print("loading %s" % module_name)
|
||||
try:
|
||||
importlib.import_module(module_name)
|
||||
except ImportError as err:
|
||||
print('Error:', err)
|
||||
print("Error:", err)
|
||||
|
||||
|
||||
@app.after_request
|
||||
def remove_header(response):
|
||||
response.headers['Server'] = 'Flask Server'
|
||||
response.headers["Server"] = "Flask Server"
|
||||
return response
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/assert-base64")
|
||||
def assert_base64():
|
||||
return 'line1\nline2\r\nline3\n'
|
||||
return "line1\nline2\r\nline3\n"
|
||||
|
@ -1,14 +1,13 @@
|
||||
from tests import app
|
||||
from flask import make_response
|
||||
|
||||
|
||||
@app.route("/assert-header")
|
||||
def assert_header():
|
||||
resp = make_response()
|
||||
resp.headers['Header1'] = 'value1'
|
||||
resp.headers['ETag'] = '"33a64df551425fcc55e4d42a148795d9f25f89d4"'
|
||||
resp.set_cookie('cookie1', 'value1')
|
||||
resp.set_cookie('cookie2', 'value2')
|
||||
resp.set_cookie('cookie3', 'value3')
|
||||
resp.headers["Header1"] = "value1"
|
||||
resp.headers["ETag"] = '"33a64df551425fcc55e4d42a148795d9f25f89d4"'
|
||||
resp.set_cookie("cookie1", "value1")
|
||||
resp.set_cookie("cookie2", "value2")
|
||||
resp.set_cookie("cookie3", "value3")
|
||||
return resp
|
||||
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/assert-json")
|
||||
def assert_json():
|
||||
return Response('''{
|
||||
return Response(
|
||||
"""{
|
||||
"count": 5,
|
||||
"success": false,
|
||||
"errors": [{"id":"error1"},{"id":"error2"}],
|
||||
@ -11,23 +13,31 @@ def assert_json():
|
||||
"duration": 1.5,
|
||||
"tags": ["test"],
|
||||
"nullable": null
|
||||
}''', mimetype='application/json')
|
||||
}""",
|
||||
mimetype="application/json",
|
||||
)
|
||||
|
||||
|
||||
@app.route("/assert-json/index")
|
||||
def assert_json_index():
|
||||
return "1"
|
||||
|
||||
|
||||
@app.route("/assert-json/list")
|
||||
def assert_json_list():
|
||||
return Response('''[
|
||||
return Response(
|
||||
"""[
|
||||
{ "id": 1, "name": "Bob"},
|
||||
{ "id": 2, "name": "Bill"}
|
||||
]''', mimetype='application/json')
|
||||
]""",
|
||||
mimetype="application/json",
|
||||
)
|
||||
|
||||
|
||||
@app.route("/assert-json/filter")
|
||||
def assert_json_filter():
|
||||
return Response('''{
|
||||
return Response(
|
||||
"""{
|
||||
"fruit": [
|
||||
{
|
||||
"name": "apple",
|
||||
@ -44,5 +54,6 @@ def assert_json_filter():
|
||||
}
|
||||
}
|
||||
]
|
||||
}''', mimetype='application/json')
|
||||
|
||||
}""",
|
||||
mimetype="application/json",
|
||||
)
|
||||
|
@ -1,13 +1,15 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/assert-match")
|
||||
def assert_match():
|
||||
return Response('''{
|
||||
return Response(
|
||||
"""{
|
||||
"date1": "2014-01-01",
|
||||
"date2": "x2014-01-01",
|
||||
"path1": "aa/bb",
|
||||
"path2": "aa\\\\bb"
|
||||
}''', mimetype='application/json')
|
||||
|
||||
|
||||
}""",
|
||||
mimetype="application/json",
|
||||
)
|
||||
|
@ -4,5 +4,4 @@ from tests import app
|
||||
|
||||
@app.route("/assert-regex")
|
||||
def assert_regex():
|
||||
return 'Hello World!'
|
||||
|
||||
return "Hello World!"
|
||||
|
@ -2,7 +2,7 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/assert-status-code")
|
||||
def assert_status_code():
|
||||
return Response('', status=201)
|
||||
|
||||
return Response("", status=201)
|
||||
|
@ -4,5 +4,4 @@ from tests import app
|
||||
|
||||
@app.route("/assert-xpath")
|
||||
def assert_xpath():
|
||||
return '<data>café</data>'
|
||||
|
||||
return "<data>café</data>"
|
||||
|
@ -1,10 +1,8 @@
|
||||
from tests import app
|
||||
from flask import request
|
||||
|
||||
@app.route('/basic-authentication')
|
||||
|
||||
@app.route("/basic-authentication")
|
||||
def basic_authentication():
|
||||
assert request.headers['Authorization'] == 'Basic Ym9iOnNlY3JldA=='
|
||||
return 'You are authenticated'
|
||||
|
||||
|
||||
|
||||
assert request.headers["Authorization"] == "Basic Ym9iOnNlY3JldA=="
|
||||
return "You are authenticated"
|
||||
|
@ -1,10 +1,8 @@
|
||||
from tests import app
|
||||
from flask import request
|
||||
|
||||
@app.route('/basic-authentication-per-request')
|
||||
|
||||
@app.route("/basic-authentication-per-request")
|
||||
def basic_authentication_per_request():
|
||||
assert request.headers['Authorization'] == 'Basic Ym9iOnNlY3JldA=='
|
||||
return 'You are authenticated'
|
||||
|
||||
|
||||
|
||||
assert request.headers["Authorization"] == "Basic Ym9iOnNlY3JldA=="
|
||||
return "You are authenticated"
|
||||
|
@ -1,7 +1,7 @@
|
||||
from tests import app
|
||||
from flask import request
|
||||
|
||||
|
||||
@app.route("/utf8_bom")
|
||||
def utf8_bom():
|
||||
return 'Hello World!'
|
||||
|
||||
return "Hello World!"
|
||||
|
@ -3,14 +3,11 @@ from flask import make_response, request
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
@app.route('/bytes')
|
||||
@app.route("/bytes")
|
||||
def bytes():
|
||||
result = BytesIO()
|
||||
result.write(b'\x01\x02\x03')
|
||||
result.write(b"\x01\x02\x03")
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
resp.content_type = 'application/octet-stream'
|
||||
resp.content_type = "application/octet-stream"
|
||||
return resp
|
||||
|
||||
|
||||
|
||||
|
@ -3,5 +3,4 @@ from tests import app
|
||||
|
||||
@app.route("/capture-and-assert")
|
||||
def capture_and_assert():
|
||||
return 'Hello World!'
|
||||
|
||||
return "Hello World!"
|
||||
|
@ -2,22 +2,21 @@ from tests import app
|
||||
from flask import make_response, request
|
||||
|
||||
|
||||
@app.route('/captures')
|
||||
@app.route("/captures")
|
||||
def captures():
|
||||
resp = make_response()
|
||||
resp.headers['Header1'] = 'value1'
|
||||
resp.headers['Header2'] = 'Hello Bob!'
|
||||
resp.headers["Header1"] = "value1"
|
||||
resp.headers["Header2"] = "Hello Bob!"
|
||||
return resp
|
||||
|
||||
|
||||
@app.route('/captures-check')
|
||||
@app.route("/captures-check")
|
||||
def captures_check():
|
||||
assert request.args.get('param1') == 'value1'
|
||||
assert request.args.get('param2') == 'Bob'
|
||||
return ''
|
||||
assert request.args.get("param1") == "value1"
|
||||
assert request.args.get("param2") == "Bob"
|
||||
return ""
|
||||
|
||||
|
||||
|
||||
@app.route('/captures-json')
|
||||
@app.route("/captures-json")
|
||||
def captures_json():
|
||||
return '{ "a_null": null, "an_object": {"id": "123"}, "a_list": [1,2,3], "an_integer": 1, "a_float": 1.1, "a_bool": true, "a_string": "hello" }'
|
||||
return '{ "a_null": null, "an_object": {"id": "123"}, "a_list": [1,2,3], "an_integer": 1, "a_float": 1.1, "a_bool": true, "a_string": "hello" }'
|
||||
|
@ -2,50 +2,60 @@ from tests import app
|
||||
from flask import make_response, request
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
@app.route("/compressed/gzip")
|
||||
def compressed_gzip():
|
||||
assert 'gzip' in request.headers['Accept-Encoding']
|
||||
assert "gzip" in request.headers["Accept-Encoding"]
|
||||
result = BytesIO()
|
||||
result.write(b'\x1f\x8b\x08\x00\xed\x0c\x84\x5f\x00\x03\xf3\x48\xcd\xc9\xc9\x57\x08\xcf\x2f\xca\x49\x51\x04\x00\xa3\x1c\x29\x1c\x0c\x00\x00\x00')
|
||||
result.write(
|
||||
b"\x1f\x8b\x08\x00\xed\x0c\x84\x5f\x00\x03\xf3\x48\xcd\xc9\xc9\x57\x08\xcf\x2f\xca\x49\x51\x04\x00\xa3\x1c\x29\x1c\x0c\x00\x00\x00"
|
||||
)
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
resp.headers['Content-Encoding'] = 'gzip'
|
||||
resp.headers["Content-Encoding"] = "gzip"
|
||||
return resp
|
||||
|
||||
|
||||
@app.route("/compressed/zlib")
|
||||
def compressed_zlib():
|
||||
assert 'deflate' in request.headers['Accept-Encoding']
|
||||
assert "deflate" in request.headers["Accept-Encoding"]
|
||||
result = BytesIO()
|
||||
result.write(b'\x78\x9c\xf3\x48\xcd\xc9\xc9\x57\x08\xcf\x2f\xca\x49\x51\x04\x00\x1c\x49\x04\x3e')
|
||||
result.write(
|
||||
b"\x78\x9c\xf3\x48\xcd\xc9\xc9\x57\x08\xcf\x2f\xca\x49\x51\x04\x00\x1c\x49\x04\x3e"
|
||||
)
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
resp.headers['Content-Encoding'] = 'deflate'
|
||||
resp.headers["Content-Encoding"] = "deflate"
|
||||
return resp
|
||||
|
||||
|
||||
@app.route("/compressed/brotli")
|
||||
def compressed_brotli():
|
||||
assert 'br' in request.headers['Accept-Encoding']
|
||||
assert "br" in request.headers["Accept-Encoding"]
|
||||
result = BytesIO()
|
||||
result.write(b'\x21\x2c\x00\x04\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21\x03')
|
||||
result.write(
|
||||
b"\x21\x2c\x00\x04\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21\x03"
|
||||
)
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
resp.headers['Content-Encoding'] = 'br'
|
||||
resp.headers["Content-Encoding"] = "br"
|
||||
return resp
|
||||
|
||||
|
||||
@app.route("/compressed/brotli_identity")
|
||||
def compressed_brotli_identity():
|
||||
assert 'br' in request.headers['Accept-Encoding']
|
||||
assert "br" in request.headers["Accept-Encoding"]
|
||||
result = BytesIO()
|
||||
|
||||
result.write(b'\x21\x2c\x00\x04\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21\x03')
|
||||
result.write(
|
||||
b"\x21\x2c\x00\x04\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21\x03"
|
||||
)
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
resp.headers['Content-Encoding'] = 'br, identity'
|
||||
resp.headers["Content-Encoding"] = "br, identity"
|
||||
return resp
|
||||
|
||||
|
||||
@app.route("/compressed/none")
|
||||
def compressed_none():
|
||||
return 'Hello World!'
|
||||
return "Hello World!"
|
||||
|
@ -4,10 +4,5 @@ from tests import app
|
||||
|
||||
@app.route("/cookie_file")
|
||||
def cookie_file():
|
||||
assert request.cookies['cookie1'] == 'valueA'
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
assert request.cookies["cookie1"] == "valueA"
|
||||
return ""
|
||||
|
@ -4,13 +4,11 @@ from tests import app
|
||||
|
||||
@app.route("/cookie-storage/assert-that-cookie1-is-valueA")
|
||||
def cookiestorage_assert_that_cookie1_is_valuea():
|
||||
assert request.cookies['cookie1'] == 'valueA'
|
||||
return ''
|
||||
assert request.cookies["cookie1"] == "valueA"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/cookie-storage/assert-that-cookie1-is-not-in-session")
|
||||
def cookiestorage_assert_that_cookie1_is_not_in_session():
|
||||
assert'cookie1' not in request.cookies
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
assert "cookie1" not in request.cookies
|
||||
return ""
|
||||
|
@ -4,29 +4,30 @@ from tests import app
|
||||
|
||||
@app.route("/cookies/set-request-cookie1-valueA")
|
||||
def set_request_cookie1_value1():
|
||||
assert request.cookies['cookie1'] == 'valueA'
|
||||
assert request.headers['Cookie'] == 'cookie1=valueA'
|
||||
return ''
|
||||
assert request.cookies["cookie1"] == "valueA"
|
||||
assert request.headers["Cookie"] == "cookie1=valueA"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/cookies/set-multiple-request-cookies")
|
||||
def set_multiple_request_cookies():
|
||||
assert request.cookies['user1'] == 'Bob'
|
||||
assert request.cookies['user2'] == 'Bill'
|
||||
assert request.headers['Cookie'] == 'user1=Bob; user2=Bill'
|
||||
return ''
|
||||
assert request.cookies["user1"] == "Bob"
|
||||
assert request.cookies["user2"] == "Bill"
|
||||
assert request.headers["Cookie"] == "user1=Bob; user2=Bill"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/cookies/set-session-cookie2-valueA")
|
||||
def set_session_cookie2_valuea():
|
||||
resp = make_response()
|
||||
resp.set_cookie('cookie2', 'valueA')
|
||||
resp.set_cookie("cookie2", "valueA")
|
||||
return resp
|
||||
|
||||
|
||||
@app.route("/cookies/set-request-cookie2-valueB")
|
||||
def set_request_cookie2_valueb():
|
||||
assert request.cookies['cookie2'] == 'valueB'
|
||||
return ''
|
||||
assert request.cookies["cookie2"] == "valueB"
|
||||
return ""
|
||||
|
||||
|
||||
# @app.route("/cookies/send-cookie2-value1")
|
||||
@ -45,49 +46,53 @@ def set_request_cookie2_valueb():
|
||||
@app.route("/cookies/delete-cookie2")
|
||||
def delete_cookie2():
|
||||
resp = make_response()
|
||||
resp.set_cookie('cookie2', '', max_age=0)
|
||||
resp.set_cookie("cookie2", "", max_age=0)
|
||||
return resp
|
||||
|
||||
|
||||
@app.route("/cookies/assert-that-cookie1-is-not-in-session")
|
||||
def assert_that_cookie1_is_not_in_session():
|
||||
assert'cookie1' not in request.cookies
|
||||
assert 'Cookie' not in request.headers
|
||||
return ''
|
||||
assert "cookie1" not in request.cookies
|
||||
assert "Cookie" not in request.headers
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/cookies/assert-that-cookie2-is-not-in-session")
|
||||
def assert_that_cookie2_is_not_in_session():
|
||||
assert'cookie2' not in request.cookies
|
||||
return ''
|
||||
assert "cookie2" not in request.cookies
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/cookies/assert-that-cookie2-is-valueA")
|
||||
def assert_that_cookie2_is_valuea():
|
||||
assert request.cookies['cookie2'] == 'valueA'
|
||||
return ''
|
||||
assert request.cookies["cookie2"] == "valueA"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/cookies/assert-that-cookie2-is-valueB")
|
||||
def assert_that_cookie2_is_valueb():
|
||||
assert request.cookies['cookie2'] == 'valueB'
|
||||
return ''
|
||||
assert request.cookies["cookie2"] == "valueB"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/cookies/assert-that-cookie2-is-valueA-and-valueB")
|
||||
def assert_that_cookie2_is_valuea_and_valueb():
|
||||
assert 'cookie2=valueA' in request.headers['Cookie']
|
||||
assert 'cookie2=valueB' in request.headers['Cookie']
|
||||
return ''
|
||||
assert "cookie2=valueA" in request.headers["Cookie"]
|
||||
assert "cookie2=valueB" in request.headers["Cookie"]
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/cookies/set-session-cookie2-valueA-subdomain")
|
||||
def set_session_cookie2_valuea_subdomain():
|
||||
resp = make_response()
|
||||
resp.set_cookie('cookie2', 'valueA', domain='myshop.orange.localhost')
|
||||
resp.set_cookie("cookie2", "valueA", domain="myshop.orange.localhost")
|
||||
return resp
|
||||
|
||||
|
||||
@app.route("/cookies/set-session-cookie2-valueA-subdomain2")
|
||||
def set_session_cookie2_valuea_subdomain2():
|
||||
resp = make_response()
|
||||
resp.set_cookie('cookie2', 'valueA', domain='orange.localhost')
|
||||
resp.set_cookie("cookie2", "valueA", domain="orange.localhost")
|
||||
return resp
|
||||
|
||||
|
||||
@ -97,11 +102,29 @@ def set_session_cookie2_valuea_subdomain2():
|
||||
@app.route("/cookies/set")
|
||||
def set_cookies():
|
||||
resp = make_response()
|
||||
resp.set_cookie('LSID', 'DQAAAKEaem_vYg', path='/accounts', secure=True, httponly=True, expires='Wed, 13 Jan 2021 22:23:01 GMT')
|
||||
resp.set_cookie('HSID', 'AYQEVnDKrdst', domain='.localhost', path='/', expires='Wed, 13 Jan 2021 22:23:01 GMT', httponly=True)
|
||||
resp.set_cookie('SSID', 'Ap4PGTEq', domain='.localhost', path='/', expires='Wed, 13 Jan 2021 22:23:01 GMT', secure=True, httponly=True)
|
||||
resp.set_cookie(
|
||||
"LSID",
|
||||
"DQAAAKEaem_vYg",
|
||||
path="/accounts",
|
||||
secure=True,
|
||||
httponly=True,
|
||||
expires="Wed, 13 Jan 2021 22:23:01 GMT",
|
||||
)
|
||||
resp.set_cookie(
|
||||
"HSID",
|
||||
"AYQEVnDKrdst",
|
||||
domain=".localhost",
|
||||
path="/",
|
||||
expires="Wed, 13 Jan 2021 22:23:01 GMT",
|
||||
httponly=True,
|
||||
)
|
||||
resp.set_cookie(
|
||||
"SSID",
|
||||
"Ap4PGTEq",
|
||||
domain=".localhost",
|
||||
path="/",
|
||||
expires="Wed, 13 Jan 2021 22:23:01 GMT",
|
||||
secure=True,
|
||||
httponly=True,
|
||||
)
|
||||
return resp
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
@app.route('/delete', methods=['DELETE'])
|
||||
|
||||
@app.route("/delete", methods=["DELETE"])
|
||||
def delete():
|
||||
return ''
|
||||
|
||||
|
||||
return ""
|
||||
|
@ -5,18 +5,14 @@ from io import BytesIO
|
||||
|
||||
@app.route("/encoding/utf8")
|
||||
def encoding_utf8():
|
||||
return 'café'
|
||||
return "café"
|
||||
|
||||
|
||||
@app.route("/encoding/latin1")
|
||||
def encoding_latin1():
|
||||
result = BytesIO()
|
||||
result.write(b'\x63\x61\x66\xe9')
|
||||
result.write(b"\x63\x61\x66\xe9")
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
resp.content_type = 'text/html; charset=ISO-8859-1'
|
||||
resp.content_type = "text/html; charset=ISO-8859-1"
|
||||
return resp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
from flask import request
|
||||
from tests import app
|
||||
|
||||
@app.route('/env-var')
|
||||
def env_var():
|
||||
assert request.args.get('name') == 'Bob'
|
||||
return ''
|
||||
|
||||
@app.route("/env-var")
|
||||
def env_var():
|
||||
assert request.args.get("name") == "Bob"
|
||||
return ""
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-base64")
|
||||
def error_assert_base64():
|
||||
return 'line1\nline2\r\nline3\n'
|
||||
return "line1\nline2\r\nline3\n"
|
||||
|
@ -2,11 +2,12 @@ from tests import app
|
||||
from flask import make_response, request
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
@app.route("/error-assert-bytearray")
|
||||
def error_assert_bytearray():
|
||||
result = BytesIO()
|
||||
result.write(b'\xff')
|
||||
result.write(b"\xff")
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
resp.content_type = 'application/octet-stream'
|
||||
return resp
|
||||
resp.content_type = "application/octet-stream"
|
||||
return resp
|
||||
|
@ -1,7 +1,8 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/error/content-encoding")
|
||||
def error_assert_content_encoding():
|
||||
headers = {'Content-Encoding': 'unknown'}
|
||||
return Response('Hello', headers=headers)
|
||||
headers = {"Content-Encoding": "unknown"}
|
||||
return Response("Hello", headers=headers)
|
||||
|
@ -1,8 +1,9 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/error-assert-decompress")
|
||||
def error_assert_decompress():
|
||||
headers = {}
|
||||
headers['Content-Encoding'] = 'gzip'
|
||||
return Response('Hello', headers=headers)
|
||||
headers["Content-Encoding"] = "gzip"
|
||||
return Response("Hello", headers=headers)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-file")
|
||||
def error_assert_file():
|
||||
return 'Hello'
|
||||
return "Hello"
|
||||
|
@ -1,6 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-header-not-found")
|
||||
def error_assert_header_not_found():
|
||||
return 'Hello World!'
|
||||
|
||||
return "Hello World!"
|
||||
|
@ -1,6 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-header-value")
|
||||
def error_assert_header_value():
|
||||
return 'Hello World!'
|
||||
|
||||
return "Hello World!"
|
||||
|
@ -1,7 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
@app.route('/error-assert/http-version')
|
||||
|
||||
@app.route("/error-assert/http-version")
|
||||
def http_version():
|
||||
return ''
|
||||
|
||||
|
||||
return ""
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-invalid-predicate-type")
|
||||
def error_assert_invalid_predicate_type():
|
||||
return ''
|
||||
return ""
|
||||
|
@ -3,12 +3,10 @@ from flask import make_response
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
@app.route('/error-assert/match-utf8')
|
||||
@app.route("/error-assert/match-utf8")
|
||||
def error_assert_match_utf8():
|
||||
result = BytesIO()
|
||||
result.write(b'\xff')
|
||||
result.write(b"\xff")
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
return resp
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-newline")
|
||||
def error_assert_newline():
|
||||
return '<p>Hello</p>\n\n'
|
||||
|
||||
return "<p>Hello</p>\n\n"
|
||||
|
@ -1,10 +1,10 @@
|
||||
from flask import request, make_response
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-query-cookie")
|
||||
def error_assert_query_cookie():
|
||||
resp = make_response()
|
||||
resp.set_cookie('cookie1', 'value1')
|
||||
resp.set_cookie('cookie2', 'value2', secure=True)
|
||||
resp.set_cookie("cookie1", "value1")
|
||||
resp.set_cookie("cookie2", "value2", secure=True)
|
||||
return resp
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-query-invalid-regex")
|
||||
def error_assert_query_invalid_regex():
|
||||
return ''
|
||||
return ""
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-query-invalid-xpath")
|
||||
def error_assert_query_invalid_xpath():
|
||||
return ''
|
||||
return ""
|
||||
|
@ -1,6 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-template-variable-not-found")
|
||||
def error_assert_template_variable_not_found():
|
||||
return ''
|
||||
|
||||
return ""
|
||||
|
@ -1,6 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-value")
|
||||
def error_assert_value():
|
||||
return '{ "values": [1,2,3], "count": 2}'
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-variable")
|
||||
def error_assert_variable():
|
||||
return ''
|
||||
|
||||
return ""
|
||||
|
@ -1,6 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-assert-xpath")
|
||||
def error_assert_xpath():
|
||||
return '<html><head><title>Test</title></head></html>'
|
||||
|
||||
return "<html><head><title>Test</title></head></html>"
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-file-read-access")
|
||||
def error_file_read_access():
|
||||
return ''
|
||||
return ""
|
||||
|
@ -1,6 +1,10 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/error-invalid-jsonpath")
|
||||
def error_invalid_jsonpath():
|
||||
return Response('{"success":false,"errors":[{"id":"error1"},{"id":"error2"}]}', mimetype='application/json')
|
||||
return Response(
|
||||
'{"success":false,"errors":[{"id":"error1"},{"id":"error2"}]}',
|
||||
mimetype="application/json",
|
||||
)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-invalid-xml")
|
||||
def error_invalid_xml():
|
||||
return ''
|
||||
return ""
|
||||
|
@ -1,11 +1,10 @@
|
||||
from tests import app
|
||||
from flask import redirect
|
||||
|
||||
@app.route('/redirect/<number>', methods=['GET'])
|
||||
|
||||
@app.route("/redirect/<number>", methods=["GET"])
|
||||
def redirect_n(number):
|
||||
n = int(number)
|
||||
if n == 0:
|
||||
return ''
|
||||
return redirect('http://localhost:8000/redirect/' + str(n-1))
|
||||
|
||||
|
||||
return ""
|
||||
return redirect("http://localhost:8000/redirect/" + str(n - 1))
|
||||
|
@ -1,8 +1,9 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/error-output-decompress")
|
||||
def error_output_decompress():
|
||||
headers = {}
|
||||
headers['Content-Encoding'] = 'gzip'
|
||||
return Response('Hello', headers=headers)
|
||||
headers["Content-Encoding"] = "gzip"
|
||||
return Response("Hello", headers=headers)
|
||||
|
@ -1,12 +1,13 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/predicate/error/type")
|
||||
def predicate_error_type():
|
||||
return '''{
|
||||
return """{
|
||||
"status": true,
|
||||
"message": "0",
|
||||
"count": 1,
|
||||
"empty": "",
|
||||
"number": 1.0,
|
||||
"list": [1,2,3]
|
||||
}'''
|
||||
}"""
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-query-header-not-found")
|
||||
def error_query_header_not_found():
|
||||
return 'Hello World!'
|
||||
return "Hello World!"
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/error-query-invalid-json")
|
||||
def error_query_invalid_json():
|
||||
return 'Hello World!'
|
||||
return "Hello World!"
|
||||
|
@ -2,10 +2,11 @@ from tests import app
|
||||
from flask import make_response
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
@app.route("/error-query-invalid-utf8")
|
||||
def error_query_invalid_utf8():
|
||||
result = BytesIO()
|
||||
result.write(b'\xff')
|
||||
result.write(b"\xff")
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
return resp
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/get-list")
|
||||
def get_list():
|
||||
return '{"values":[1,2,3]}'
|
||||
|
@ -1,9 +1,8 @@
|
||||
from tests import app
|
||||
import time
|
||||
|
||||
@app.route('/timeout')
|
||||
|
||||
@app.route("/timeout")
|
||||
def timeout():
|
||||
time.sleep(2)
|
||||
return ''
|
||||
|
||||
|
||||
return ""
|
||||
|
@ -1,11 +1,10 @@
|
||||
from tests import app
|
||||
from flask import request
|
||||
|
||||
@app.route("/expect", methods=['POST'])
|
||||
|
||||
@app.route("/expect", methods=["POST"])
|
||||
def expect():
|
||||
assert request.headers['Expect'] == '100-continue'
|
||||
assert request.headers["Expect"] == "100-continue"
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == '''data'''
|
||||
return ''
|
||||
|
||||
|
||||
assert s == """data"""
|
||||
return ""
|
||||
|
@ -1,6 +1,7 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/float")
|
||||
def float():
|
||||
return '[ -2.2, 0.0, 0.0000000000000001, 0.000000000000001, 0.333, 0.3333333333333333, 0.333333333333333333, 1.0, 1.001, 1.07, 1.070, 1.1, 1.5 ]'
|
||||
return "[ -2.2, 0.0, 0.0000000000000001, 0.000000000000001, 0.333, 0.3333333333333333, 0.333333333333333333, 1.0, 1.001, 1.07, 1.070, 1.1, 1.5 ]"
|
||||
|
@ -1,14 +1,17 @@
|
||||
from tests import app
|
||||
from flask import redirect
|
||||
|
||||
@app.route('/follow-redirect')
|
||||
|
||||
@app.route("/follow-redirect")
|
||||
def follow_redirect():
|
||||
return redirect('http://localhost:8000/following-redirect')
|
||||
return redirect("http://localhost:8000/following-redirect")
|
||||
|
||||
@app.route('/following-redirect')
|
||||
|
||||
@app.route("/following-redirect")
|
||||
def following_redirect():
|
||||
return redirect('http://localhost:8000/followed-redirect')
|
||||
return redirect("http://localhost:8000/followed-redirect")
|
||||
|
||||
@app.route('/followed-redirect')
|
||||
|
||||
@app.route("/followed-redirect")
|
||||
def followed_redirect():
|
||||
return 'Followed redirect!'
|
||||
return "Followed redirect!"
|
||||
|
@ -1,14 +1,13 @@
|
||||
from tests import app
|
||||
from flask import request
|
||||
|
||||
@app.route("/form-params", methods=['POST'])
|
||||
|
||||
@app.route("/form-params", methods=["POST"])
|
||||
def form_params():
|
||||
assert request.form['param1'] == 'value1'
|
||||
assert request.form['param2'] == ''
|
||||
assert request.form['param3'] == 'a=b'
|
||||
assert request.form['param4'] == 'a%3db'
|
||||
assert request.form['values[0]'] == '0'
|
||||
assert request.form['values[1]'] == '1'
|
||||
return ''
|
||||
|
||||
|
||||
assert request.form["param1"] == "value1"
|
||||
assert request.form["param2"] == ""
|
||||
assert request.form["param3"] == "a=b"
|
||||
assert request.form["param4"] == "a%3db"
|
||||
assert request.form["values[0]"] == "0"
|
||||
assert request.form["values[1]"] == "1"
|
||||
return ""
|
||||
|
@ -1,43 +1,49 @@
|
||||
# coding=utf-8
|
||||
from flask import request,make_response
|
||||
from flask import request, make_response
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/default-headers")
|
||||
def default_headers():
|
||||
assert 'hurl' in request.headers['User-Agent'] or 'curl' in request.headers['User-Agent']
|
||||
assert request.headers['Host'] == 'localhost:8000'
|
||||
assert 'Content-Length' not in request.headers
|
||||
return ''
|
||||
assert (
|
||||
"hurl" in request.headers["User-Agent"]
|
||||
or "curl" in request.headers["User-Agent"]
|
||||
)
|
||||
assert request.headers["Host"] == "localhost:8000"
|
||||
assert "Content-Length" not in request.headers
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/custom-headers")
|
||||
def custom_headers():
|
||||
# TODO: what is expected when request header has multiple values ?
|
||||
assert request.headers['Fruit'] == "Raspberry,Apple,Banana,Grape"
|
||||
assert request.headers['Color'] == 'Green'
|
||||
return ''
|
||||
assert request.headers["Fruit"] == "Raspberry,Apple,Banana,Grape"
|
||||
assert request.headers["Color"] == "Green"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/custom-headers-utf8")
|
||||
def custom_headers_utf8():
|
||||
assert len(request.headers['Beverage']) == 5
|
||||
assert request.headers['Beverage'] == '\x63\x61\x66\xc3\xa9'
|
||||
return ''
|
||||
assert len(request.headers["Beverage"]) == 5
|
||||
assert request.headers["Beverage"] == "\x63\x61\x66\xc3\xa9"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/custom-headers-value")
|
||||
def custom_headers_value():
|
||||
assert request.headers['Id'] == '#123'
|
||||
return ''
|
||||
assert request.headers["Id"] == "#123"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/custom-headers-quote")
|
||||
def custom_headers_quotes():
|
||||
assert request.headers['Header1'] == "'"
|
||||
return ''
|
||||
assert request.headers["Header1"] == "'"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/response-headers")
|
||||
def response_headers():
|
||||
resp = make_response()
|
||||
#resp.headers['Beverage'] = '\x63\x61\x66\xc3\xa9'
|
||||
resp.headers['Beverage'] = 'cafe'
|
||||
return resp
|
||||
# resp.headers['Beverage'] = '\x63\x61\x66\xc3\xa9'
|
||||
resp.headers["Beverage"] = "cafe"
|
||||
return resp
|
||||
|
@ -1,10 +1,10 @@
|
||||
from tests import app
|
||||
from flask import request
|
||||
|
||||
|
||||
@app.route("/hello")
|
||||
def hello():
|
||||
assert 'Content-Type' not in request.headers
|
||||
assert 'Content-Length' not in request.headers
|
||||
assert "Content-Type" not in request.headers
|
||||
assert "Content-Length" not in request.headers
|
||||
assert len(request.data) == 0
|
||||
return 'Hello World!'
|
||||
|
||||
return "Hello World!"
|
||||
|
@ -1,6 +1,7 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/ignore_asserts")
|
||||
def ignore_asserts():
|
||||
return 'Hello'
|
||||
return "Hello"
|
||||
|
@ -1,7 +1,8 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/include")
|
||||
def include():
|
||||
headers = {'Date': 'DATE'}
|
||||
return Response('Hello', headers=headers)
|
||||
headers = {"Date": "DATE"}
|
||||
return Response("Hello", headers=headers)
|
||||
|
@ -3,14 +3,12 @@ from flask import make_response
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
@app.route('/large')
|
||||
@app.route("/large")
|
||||
def large():
|
||||
result = BytesIO()
|
||||
for _ in range(1024*1024*32):
|
||||
result.write(b'0123456789abcdef')
|
||||
for _ in range(1024 * 1024 * 32):
|
||||
result.write(b"0123456789abcdef")
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
resp.content_type = 'application/octet-stream'
|
||||
resp.content_type = "application/octet-stream"
|
||||
return resp
|
||||
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/multilines")
|
||||
def multilines():
|
||||
return 'line1\nline2\nline3\n'
|
||||
|
||||
|
||||
return "line1\nline2\nline3\n"
|
||||
|
@ -2,27 +2,26 @@
|
||||
from tests import app
|
||||
from flask import request
|
||||
|
||||
@app.route("/multipart-form-data", methods=['POST'])
|
||||
|
||||
@app.route("/multipart-form-data", methods=["POST"])
|
||||
def multipart_form_data():
|
||||
|
||||
assert request.form['key1'] == 'value1'
|
||||
assert 'Expect' not in request.headers
|
||||
assert request.form["key1"] == "value1"
|
||||
assert "Expect" not in request.headers
|
||||
|
||||
upload1 = request.files['upload1']
|
||||
assert upload1.filename == 'data.txt'
|
||||
assert upload1.content_type == 'text/plain'
|
||||
assert upload1.read() == b'Hello World!'
|
||||
upload1 = request.files["upload1"]
|
||||
assert upload1.filename == "data.txt"
|
||||
assert upload1.content_type == "text/plain"
|
||||
assert upload1.read() == b"Hello World!"
|
||||
|
||||
upload2 = request.files['upload2']
|
||||
assert upload2.filename == 'data.html'
|
||||
assert upload2.content_type == 'text/html'
|
||||
assert upload2.read() == b'<div>Hello <b>World</b>!</div>'
|
||||
|
||||
upload3 = request.files['upload3']
|
||||
assert upload3.filename == 'data.txt'
|
||||
assert upload3.content_type == 'text/html'
|
||||
assert upload3.read() == b'Hello World!'
|
||||
|
||||
return ''
|
||||
upload2 = request.files["upload2"]
|
||||
assert upload2.filename == "data.html"
|
||||
assert upload2.content_type == "text/html"
|
||||
assert upload2.read() == b"<div>Hello <b>World</b>!</div>"
|
||||
|
||||
upload3 = request.files["upload3"]
|
||||
assert upload3.filename == "data.txt"
|
||||
assert upload3.content_type == "text/html"
|
||||
assert upload3.read() == b"Hello World!"
|
||||
|
||||
return ""
|
||||
|
@ -2,12 +2,12 @@ from tests import app
|
||||
from flask import make_response, request
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
@app.route("/non-utf8")
|
||||
def non_utf8():
|
||||
|
||||
result = BytesIO()
|
||||
result.write(b'\x41\x0a\xe9\x0a\xaa')
|
||||
result.write(b"\x41\x0a\xe9\x0a\xaa")
|
||||
data = result.getvalue()
|
||||
resp = make_response(data)
|
||||
return resp
|
||||
|
||||
|
@ -2,19 +2,18 @@ from tests import app
|
||||
from flask import request
|
||||
|
||||
|
||||
@app.route("/output/endpoint1", methods=['POST'])
|
||||
@app.route("/output/endpoint1", methods=["POST"])
|
||||
def output_endpoint1():
|
||||
assert request.headers['Content-Type'] == 'application/json'
|
||||
assert request.headers["Content-Type"] == "application/json"
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == '{ "user": "bob" }'
|
||||
return app.response_class(
|
||||
headers={'date': 'DATE1'},
|
||||
response='Response endpoint1\n'
|
||||
headers={"date": "DATE1"}, response="Response endpoint1\n"
|
||||
)
|
||||
|
||||
|
||||
@app.route("/output/endpoint2")
|
||||
def output_endpoint2():
|
||||
return app.response_class(
|
||||
headers={'date': 'DATE2'},
|
||||
response='Response endpoint2\n'
|
||||
headers={"date": "DATE2"}, response="Response endpoint2\n"
|
||||
)
|
||||
|
@ -2,13 +2,12 @@ from flask import request, make_response
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route('/patch/file.txt', methods=['PATCH'])
|
||||
@app.route("/patch/file.txt", methods=["PATCH"])
|
||||
def patch():
|
||||
assert request.headers['Host'] == 'www.example.com'
|
||||
assert request.headers['Content-Type'] == 'application/example'
|
||||
assert request.headers['If-Match'] == '"e0023aa4e"'
|
||||
assert request.headers["Host"] == "www.example.com"
|
||||
assert request.headers["Content-Type"] == "application/example"
|
||||
assert request.headers["If-Match"] == '"e0023aa4e"'
|
||||
resp = make_response()
|
||||
resp.headers['Content-Location'] = '/file.txt'
|
||||
resp.headers['ETag'] = '"e0023aa4f"'
|
||||
resp.headers["Content-Location"] = "/file.txt"
|
||||
resp.headers["ETag"] = '"e0023aa4f"'
|
||||
return resp, 204
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
from flask import request
|
||||
from tests import app
|
||||
|
||||
@app.route('/post-base64', methods=['POST'])
|
||||
def post_base64():
|
||||
assert request.data == b'Hello World!'
|
||||
return ''
|
||||
|
||||
@app.route("/post-base64", methods=["POST"])
|
||||
def post_base64():
|
||||
assert request.data == b"Hello World!"
|
||||
return ""
|
||||
|
@ -1,8 +1,8 @@
|
||||
from flask import request
|
||||
from tests import app
|
||||
|
||||
@app.route('/post-bytes', methods=['POST'])
|
||||
def post_bytes():
|
||||
assert request.data == b'\x01\x02\x03'
|
||||
return ''
|
||||
|
||||
@app.route("/post-bytes", methods=["POST"])
|
||||
def post_bytes():
|
||||
assert request.data == b"\x01\x02\x03"
|
||||
return ""
|
||||
|
@ -1,8 +1,8 @@
|
||||
from flask import request
|
||||
from tests import app
|
||||
|
||||
@app.route('/post-file', methods=['POST'])
|
||||
def post_file():
|
||||
assert request.data == b'Hello World!'
|
||||
return ''
|
||||
|
||||
@app.route("/post-file", methods=["POST"])
|
||||
def post_file():
|
||||
assert request.data == b"Hello World!"
|
||||
return ""
|
||||
|
@ -2,74 +2,86 @@ from flask import request
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route('/post-json', methods=['POST'])
|
||||
@app.route("/post-json", methods=["POST"])
|
||||
def post_json():
|
||||
assert request.headers['Content-Type'] == 'application/json'
|
||||
assert request.headers["Content-Type"] == "application/json"
|
||||
s = request.data.decode("utf-8")
|
||||
print(s)
|
||||
assert s == '''{
|
||||
assert (
|
||||
s
|
||||
== """{
|
||||
"name": "Bob",
|
||||
"password": "&secret<>",
|
||||
"age": 30,
|
||||
"strict": true,
|
||||
"spacing": "\\n",
|
||||
"g_clef": "\\uD834\\uDD1E"
|
||||
}'''
|
||||
return ''
|
||||
}"""
|
||||
)
|
||||
return ""
|
||||
|
||||
|
||||
@app.route('/post-json-array', methods=['POST'])
|
||||
@app.route("/post-json-array", methods=["POST"])
|
||||
def post_json_array():
|
||||
assert request.headers['Content-Type'] == 'application/json'
|
||||
assert request.headers["Content-Type"] == "application/json"
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == '[1,2,3]'
|
||||
return ''
|
||||
assert s == "[1,2,3]"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route('/post-json-string', methods=['POST'])
|
||||
@app.route("/post-json-string", methods=["POST"])
|
||||
def post_json_string():
|
||||
assert request.headers['Content-Type'] == 'application/json'
|
||||
assert request.headers["Content-Type"] == "application/json"
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == '"Hello"'
|
||||
return ''
|
||||
return ""
|
||||
|
||||
|
||||
@app.route('/post-json-number', methods=['POST'])
|
||||
@app.route("/post-json-number", methods=["POST"])
|
||||
def post_json_number():
|
||||
assert request.headers['Content-Type'] == 'application/json'
|
||||
assert request.headers["Content-Type"] == "application/json"
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == '100'
|
||||
return ''
|
||||
assert s == "100"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route('/post-json-boolean', methods=['POST'])
|
||||
@app.route("/post-json-boolean", methods=["POST"])
|
||||
def post_json_boolean():
|
||||
assert request.headers['Content-Type'] == 'application/json'
|
||||
assert request.headers["Content-Type"] == "application/json"
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == 'true'
|
||||
return ''
|
||||
assert s == "true"
|
||||
return ""
|
||||
|
||||
@app.route('/post-json-numbers', methods=['POST'])
|
||||
|
||||
@app.route("/post-json-numbers", methods=["POST"])
|
||||
def post_json_numbers():
|
||||
assert request.headers['Content-Type'] == 'application/json'
|
||||
assert request.headers["Content-Type"] == "application/json"
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == '''{
|
||||
assert (
|
||||
s
|
||||
== """{
|
||||
"natural": 100,
|
||||
"negative": -1,
|
||||
"float": "3.333333333333333",
|
||||
"exponent": 100e100
|
||||
}'''
|
||||
return ''
|
||||
}"""
|
||||
)
|
||||
return ""
|
||||
|
||||
@app.route('/get-name')
|
||||
|
||||
@app.route("/get-name")
|
||||
def get_name():
|
||||
return 'Bob'
|
||||
return "Bob"
|
||||
|
||||
@app.route('/check_name', methods=['POST'])
|
||||
|
||||
@app.route("/check_name", methods=["POST"])
|
||||
def check_name():
|
||||
assert request.headers['Content-Type'] == 'application/json'
|
||||
assert request.headers["Content-Type"] == "application/json"
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == '''{
|
||||
assert (
|
||||
s
|
||||
== """{
|
||||
"name": "Bob"
|
||||
}'''
|
||||
return ''
|
||||
}"""
|
||||
)
|
||||
return ""
|
||||
|
@ -1,13 +1,14 @@
|
||||
from flask import request
|
||||
from tests import app
|
||||
|
||||
@app.route('/post-multilines', methods=['POST'])
|
||||
|
||||
@app.route("/post-multilines", methods=["POST"])
|
||||
def post_multilines():
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == "name,age\nbob,10\nbill,22\n"
|
||||
return ''
|
||||
return ""
|
||||
|
||||
@app.route('/get-bob-age', methods=['GET'])
|
||||
|
||||
@app.route("/get-bob-age", methods=["GET"])
|
||||
def get_bob_age():
|
||||
return '10'
|
||||
|
||||
return "10"
|
||||
|
@ -2,16 +2,20 @@
|
||||
from flask import request
|
||||
from tests import app
|
||||
|
||||
@app.route('/post-xml', methods=['POST'])
|
||||
|
||||
@app.route("/post-xml", methods=["POST"])
|
||||
def post_xml():
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == '''<?xml version="1.0"?>
|
||||
<drink>caf\u00e9</drink>'''
|
||||
return ''
|
||||
assert (
|
||||
s
|
||||
== """<?xml version="1.0"?>
|
||||
<drink>caf\u00e9</drink>"""
|
||||
)
|
||||
return ""
|
||||
|
||||
@app.route('/post-xml-no-prolog', methods=['POST'])
|
||||
|
||||
@app.route("/post-xml-no-prolog", methods=["POST"])
|
||||
def post_xml_no_prolog():
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == '''<drink>caf\u00e9</drink>'''
|
||||
return ''
|
||||
|
||||
assert s == """<drink>caf\u00e9</drink>"""
|
||||
return ""
|
||||
|
@ -1,16 +1,17 @@
|
||||
from flask import request
|
||||
from tests import app
|
||||
|
||||
@app.route('/predicates-string')
|
||||
|
||||
@app.route("/predicates-string")
|
||||
def predicates_string():
|
||||
return 'Hello World!'
|
||||
return "Hello World!"
|
||||
|
||||
@app.route('/predicates-string-empty')
|
||||
|
||||
@app.route("/predicates-string-empty")
|
||||
def predicates_string_empty():
|
||||
return ''
|
||||
return ""
|
||||
|
||||
@app.route('/predicates-string-unicode')
|
||||
|
||||
@app.route("/predicates-string-unicode")
|
||||
def predicates_string_unicode():
|
||||
return '\u2708'
|
||||
|
||||
|
||||
return "\u2708"
|
||||
|
@ -1,8 +1,8 @@
|
||||
from tests import app
|
||||
from flask import request
|
||||
|
||||
|
||||
@app.route("/proxy")
|
||||
def proxy():
|
||||
assert request.headers['From-Proxy'] == 'Hello'
|
||||
return ''
|
||||
|
||||
assert request.headers["From-Proxy"] == "Hello"
|
||||
return ""
|
||||
|
@ -1,5 +1,6 @@
|
||||
from tests import app
|
||||
|
||||
@app.route('/put', methods=['PUT'])
|
||||
|
||||
@app.route("/put", methods=["PUT"])
|
||||
def put():
|
||||
return ''
|
||||
return ""
|
||||
|
@ -1,17 +1,19 @@
|
||||
from tests import app
|
||||
from flask import request
|
||||
|
||||
|
||||
@app.route("/querystring-params")
|
||||
def querystring_params():
|
||||
assert request.args.get('param1') == 'value1'
|
||||
assert request.args.get('param2') == ''
|
||||
assert request.args.get('param3') == 'a=b'
|
||||
assert request.args.get('param4') == '1,2,3'
|
||||
return ''
|
||||
assert request.args.get("param1") == "value1"
|
||||
assert request.args.get("param2") == ""
|
||||
assert request.args.get("param3") == "a=b"
|
||||
assert request.args.get("param4") == "1,2,3"
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/querystring-params-encoded")
|
||||
def querystring_params_encoded():
|
||||
assert request.args.get('value1') == '/'
|
||||
assert request.args.get('value2') == '/'
|
||||
assert request.args.get('value3') == '/'
|
||||
return ''
|
||||
assert request.args.get("value1") == "/"
|
||||
assert request.args.get("value2") == "/"
|
||||
assert request.args.get("value3") == "/"
|
||||
return ""
|
||||
|
@ -1,10 +1,12 @@
|
||||
from tests import app
|
||||
from flask import redirect
|
||||
|
||||
@app.route('/redirect')
|
||||
def redirectme():
|
||||
return redirect('http://localhost:8000/redirected')
|
||||
|
||||
@app.route('/redirected')
|
||||
@app.route("/redirect")
|
||||
def redirectme():
|
||||
return redirect("http://localhost:8000/redirected")
|
||||
|
||||
|
||||
@app.route("/redirected")
|
||||
def redirected():
|
||||
return ''
|
||||
return ""
|
||||
|
@ -1,10 +1,12 @@
|
||||
from tests import app
|
||||
from flask import Response
|
||||
|
||||
|
||||
@app.route("/subquery-count")
|
||||
def subquery_count():
|
||||
return Response('''{
|
||||
return Response(
|
||||
"""{
|
||||
"users": ["Bob", "Bill", "Bruce"]
|
||||
}''', mimetype='application/json')
|
||||
|
||||
|
||||
}""",
|
||||
mimetype="application/json",
|
||||
)
|
||||
|
@ -1,10 +1,12 @@
|
||||
# coding=utf-8
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/~user")
|
||||
def url_with_tilde():
|
||||
return 'user'
|
||||
return "user"
|
||||
|
||||
|
||||
@app.route("/!$&()*+,;=:@[]")
|
||||
def url_weird():
|
||||
return 'weird'
|
||||
return "weird"
|
||||
|
@ -1,12 +1,14 @@
|
||||
from tests import app
|
||||
from flask import request
|
||||
|
||||
|
||||
@app.route("/user-agent/a")
|
||||
def useragent_a():
|
||||
assert 'Mozilla/5.0 A' == request.headers['User-Agent']
|
||||
return ''
|
||||
assert "Mozilla/5.0 A" == request.headers["User-Agent"]
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/user-agent/b")
|
||||
def useragent_b():
|
||||
assert 'Mozilla/5.0 B' == request.headers['User-Agent']
|
||||
return ''
|
||||
assert "Mozilla/5.0 B" == request.headers["User-Agent"]
|
||||
return ""
|
||||
|
@ -1,6 +1,7 @@
|
||||
# coding=utf-8
|
||||
from tests import app
|
||||
|
||||
|
||||
@app.route("/utf8")
|
||||
def utf8():
|
||||
return '<data>café</data>'
|
||||
return "<data>café</data>"
|
||||
|
@ -3,25 +3,22 @@ from tests import app
|
||||
import json
|
||||
|
||||
|
||||
@app.route('/variables', methods=['POST'])
|
||||
@app.route("/variables", methods=["POST"])
|
||||
def variables():
|
||||
assert request.headers['Content-Type'] == 'application/json'
|
||||
assert request.headers['Name'] == 'Jennifer'
|
||||
assert request.headers['Age'] == '30'
|
||||
assert request.headers['Female'] == 'true'
|
||||
assert request.headers['Id'] == '123'
|
||||
assert request.headers['Height'] == '1.7'
|
||||
assert request.headers['A_null'] == 'null'
|
||||
assert request.headers["Content-Type"] == "application/json"
|
||||
assert request.headers["Name"] == "Jennifer"
|
||||
assert request.headers["Age"] == "30"
|
||||
assert request.headers["Female"] == "true"
|
||||
assert request.headers["Id"] == "123"
|
||||
assert request.headers["Height"] == "1.7"
|
||||
assert request.headers["A_null"] == "null"
|
||||
|
||||
s = request.data.decode("utf-8")
|
||||
data = json.loads(s)
|
||||
assert data['name'] == 'Jennifer'
|
||||
assert data['age'] == 30
|
||||
assert data['female'] == True
|
||||
assert data['id'] == '123'
|
||||
assert data['height'] == 1.7
|
||||
assert data['a_null'] is None
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
assert data["name"] == "Jennifer"
|
||||
assert data["age"] == 30
|
||||
assert data["female"] == True
|
||||
assert data["id"] == "123"
|
||||
assert data["height"] == 1.7
|
||||
assert data["a_null"] is None
|
||||
return ""
|
||||
|
Loading…
Reference in New Issue
Block a user