sanic/tests/test_utf8.py

55 lines
1.2 KiB
Python
Raw Normal View History

2018-08-26 15:43:14 +01:00
from json import dumps as json_dumps
from sanic.response import text
# ------------------------------------------------------------ #
# UTF-8
# ------------------------------------------------------------ #
2018-08-26 15:43:14 +01:00
def test_utf8_query_string(app):
@app.route('/')
async def handler(request):
return text('OK')
2017-02-14 19:51:20 +00:00
request, response = app.test_client.get('/', params=[("utf8", '')])
assert request.args.get('utf8') == ''
2018-08-26 15:43:14 +01:00
def test_utf8_response(app):
@app.route('/')
async def handler(request):
return text('')
2017-02-14 19:51:20 +00:00
request, response = app.test_client.get('/')
assert response.text == ''
2018-08-26 15:43:14 +01:00
def skip_test_utf8_route(app):
@app.route('/')
async def handler(request):
return text('OK')
# UTF-8 Paths are not supported
2017-02-14 19:51:20 +00:00
request, response = app.test_client.get('/✓')
assert response.text == 'OK'
2018-08-26 15:43:14 +01:00
def test_utf8_post_json(app):
@app.route('/')
async def handler(request):
return text('OK')
payload = {'test': ''}
headers = {'content-type': 'application/json'}
2017-02-14 19:51:20 +00:00
request, response = app.test_client.get(
'/',
data=json_dumps(payload), headers=headers)
assert request.json.get('test') == ''
assert response.text == 'OK'