sanic/tests/test_test_client_port.py
Adam Hopkins ccd4c9615c Create requests-async based TestClient, remove aiohttp dependency, drop Python 3.5
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
2019-04-30 15:26:06 +03:00

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