2019-03-04 21:23:03 +00:00
|
|
|
from sanic.response import json, text
|
2019-04-23 22:44:42 +01:00
|
|
|
from sanic.testing import PORT, SanicTestClient
|
|
|
|
|
2019-03-04 21:23:03 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------ #
|
|
|
|
# UTF-8
|
|
|
|
# ------------------------------------------------------------ #
|
|
|
|
|
|
|
|
|
|
|
|
def test_test_client_port_none(app):
|
2019-04-23 22:44:42 +01:00
|
|
|
@app.get("/get")
|
2019-03-04 21:23:03 +00:00
|
|
|
def handler(request):
|
2019-04-23 22:44:42 +01:00
|
|
|
return text("OK")
|
2019-03-04 21:23:03 +00:00
|
|
|
|
|
|
|
test_client = SanicTestClient(app, port=None)
|
|
|
|
|
2019-04-23 22:44:42 +01:00
|
|
|
request, response = test_client.get("/get")
|
|
|
|
assert response.text == "OK"
|
2019-03-04 21:23:03 +00:00
|
|
|
|
2019-04-23 22:44:42 +01:00
|
|
|
request, response = test_client.post("/get")
|
2019-03-04 21:23:03 +00:00
|
|
|
assert response.status == 405
|
|
|
|
|
|
|
|
|
|
|
|
def test_test_client_port_default(app):
|
2019-04-23 22:44:42 +01:00
|
|
|
@app.get("/get")
|
2019-03-04 21:23:03 +00:00
|
|
|
def handler(request):
|
2019-04-23 22:44:42 +01:00
|
|
|
return json(request.transport.get_extra_info("sockname")[1])
|
2019-03-04 21:23:03 +00:00
|
|
|
|
|
|
|
test_client = SanicTestClient(app)
|
|
|
|
assert test_client.port == PORT
|
|
|
|
|
2019-04-23 22:44:42 +01:00
|
|
|
request, response = test_client.get("/get")
|
2019-03-04 21:23:03 +00:00
|
|
|
assert response.json == PORT
|