forked from sanic-org/sanic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_test_client_port.py
34 lines (23 loc) · 946 Bytes
/
test_test_client_port.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 # Can be None before request
request, response = test_client.get("/get")
assert test_client.port > 0
assert response.json == test_client.port