2018-08-26 15:43:14 +01:00
|
|
|
from json import dumps as json_dumps
|
2019-04-23 22:44:42 +01:00
|
|
|
|
2018-08-26 15:43:14 +01:00
|
|
|
from sanic.response import text
|
2016-10-14 11:23:48 +01:00
|
|
|
|
|
|
|
# ------------------------------------------------------------ #
|
|
|
|
# UTF-8
|
|
|
|
# ------------------------------------------------------------ #
|
|
|
|
|
2016-10-15 03:53:49 +01:00
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
def test_utf8_query_string(app):
|
|
|
|
@app.route("/")
|
2016-10-15 03:53:49 +01:00
|
|
|
async def handler(request):
|
2018-12-30 11:18:06 +00:00
|
|
|
return text("OK")
|
2016-10-14 11:23:48 +01:00
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
request, response = app.test_client.get("/", params=[("utf8", "✓")])
|
|
|
|
assert request.args.get("utf8") == "✓"
|
2016-10-14 11:23:48 +01:00
|
|
|
|
|
|
|
|
2018-08-26 15:43:14 +01:00
|
|
|
def test_utf8_response(app):
|
2018-12-30 11:18:06 +00:00
|
|
|
@app.route("/")
|
2016-10-15 03:53:49 +01:00
|
|
|
async def handler(request):
|
2018-12-30 11:18:06 +00:00
|
|
|
return text("✓")
|
2016-10-15 03:53:49 +01:00
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
request, response = app.test_client.get("/")
|
|
|
|
assert response.text == "✓"
|
2016-10-14 11:23:48 +01:00
|
|
|
|
|
|
|
|
2018-08-26 15:43:14 +01:00
|
|
|
def skip_test_utf8_route(app):
|
2018-12-30 11:18:06 +00:00
|
|
|
@app.route("/")
|
2016-10-15 03:53:49 +01:00
|
|
|
async def handler(request):
|
2018-12-30 11:18:06 +00:00
|
|
|
return text("OK")
|
2016-10-14 11:23:48 +01:00
|
|
|
|
2016-10-15 03:53:49 +01:00
|
|
|
# UTF-8 Paths are not supported
|
2018-12-30 11:18:06 +00:00
|
|
|
request, response = app.test_client.get("/✓")
|
|
|
|
assert response.text == "OK"
|
2016-10-14 11:23:48 +01:00
|
|
|
|
|
|
|
|
2018-08-26 15:43:14 +01:00
|
|
|
def test_utf8_post_json(app):
|
2019-12-21 03:23:52 +00:00
|
|
|
@app.post("/")
|
2016-10-15 03:53:49 +01:00
|
|
|
async def handler(request):
|
2018-12-30 11:18:06 +00:00
|
|
|
return text("OK")
|
2016-10-14 11:23:48 +01:00
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
payload = {"test": "✓"}
|
|
|
|
headers = {"content-type": "application/json"}
|
2016-10-14 11:23:48 +01:00
|
|
|
|
2019-12-21 03:23:52 +00:00
|
|
|
request, response = app.test_client.post(
|
2018-12-30 11:18:06 +00:00
|
|
|
"/", data=json_dumps(payload), headers=headers
|
|
|
|
)
|
2016-10-14 11:23:48 +01:00
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
assert request.json.get("test") == "✓"
|
|
|
|
assert response.text == "OK"
|