ccd4c9615c
Update all tests to be compatible with requests-async Cleanup testing client changes with black and isort Remove Python 3.5 and other meta doc cleanup rename pyproject and fix pep517 error Add black config to tox.ini Cleanup tests and remove aiohttp tox.ini change for easier development commands Remove aiohttp from changelog and requirements Cleanup imports and Makefile
36 lines
887 B
Python
36 lines
887 B
Python
import socket
|
|
|
|
from sanic.response import json, text
|
|
from sanic.testing import PORT, SanicTestClient
|
|
|
|
|
|
# ------------------------------------------------------------ #
|
|
# UTF-8
|
|
# ------------------------------------------------------------ #
|
|
|
|
|
|
def test_test_client_port_none(app):
|
|
@app.get("/get")
|
|
def handler(request):
|
|
return text("OK")
|
|
|
|
test_client = SanicTestClient(app, port=None)
|
|
|
|
request, response = test_client.get("/get")
|
|
assert response.text == "OK"
|
|
|
|
request, response = test_client.post("/get")
|
|
assert response.status == 405
|
|
|
|
|
|
def test_test_client_port_default(app):
|
|
@app.get("/get")
|
|
def handler(request):
|
|
return json(request.transport.get_extra_info("sockname")[1])
|
|
|
|
test_client = SanicTestClient(app)
|
|
assert test_client.port == PORT
|
|
|
|
request, response = test_client.get("/get")
|
|
assert response.json == PORT
|