sanic/tests/test_bad_request.py

22 lines
591 B
Python
Raw Normal View History

2016-12-18 00:25:39 +00:00
import asyncio
2018-08-26 15:43:14 +01:00
def test_bad_request_response(app):
2016-12-18 00:25:39 +00:00
lines = []
2018-10-22 21:25:38 +01:00
2018-12-30 11:18:06 +00:00
@app.listener("after_server_start")
2016-12-18 00:25:39 +00:00
async def _request(sanic, loop):
2018-12-30 11:18:06 +00:00
connect = asyncio.open_connection("127.0.0.1", 42101)
2016-12-18 00:25:39 +00:00
reader, writer = await connect
2018-12-30 11:18:06 +00:00
writer.write(b"not http")
2016-12-18 00:25:39 +00:00
while True:
line = await reader.readline()
if not line:
break
lines.append(line)
app.stop()
2018-12-30 11:18:06 +00:00
app.run(host="127.0.0.1", port=42101, debug=False)
assert lines[0] == b"HTTP/1.1 400 Bad Request\r\n"
assert b"Bad Request" in lines[-1]