fix unit tests
This commit is contained in:
parent
181adebf82
commit
268d254d85
|
@ -274,10 +274,6 @@ class Request(dict):
|
||||||
self._remote_addr = ""
|
self._remote_addr = ""
|
||||||
return self._remote_addr
|
return self._remote_addr
|
||||||
|
|
||||||
@property
|
|
||||||
def stream(self):
|
|
||||||
return self.stream
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scheme(self):
|
def scheme(self):
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -4,6 +4,8 @@ from sanic.views import CompositionView
|
||||||
from sanic.views import HTTPMethodView
|
from sanic.views import HTTPMethodView
|
||||||
from sanic.views import stream as stream_decorator
|
from sanic.views import stream as stream_decorator
|
||||||
from sanic.response import stream, text
|
from sanic.response import stream, text
|
||||||
|
from sanic.request import StreamBuffer
|
||||||
|
|
||||||
|
|
||||||
data = "abc" * 100000
|
data = "abc" * 100000
|
||||||
|
|
||||||
|
@ -19,10 +21,10 @@ def test_request_stream_method_view(app):
|
||||||
|
|
||||||
@stream_decorator
|
@stream_decorator
|
||||||
async def post(self, request):
|
async def post(self, request):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
result = ''
|
result = ''
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
result += body.decode('utf-8')
|
result += body.decode('utf-8')
|
||||||
|
@ -71,11 +73,11 @@ def test_request_stream_app(app):
|
||||||
|
|
||||||
@app.post('/post/<id>', stream=True)
|
@app.post('/post/<id>', stream=True)
|
||||||
async def post(request, id):
|
async def post(request, id):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
|
|
||||||
async def streaming(response):
|
async def streaming(response):
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
await response.write(body.decode('utf-8'))
|
await response.write(body.decode('utf-8'))
|
||||||
|
@ -88,11 +90,11 @@ def test_request_stream_app(app):
|
||||||
|
|
||||||
@app.put('/put', stream=True)
|
@app.put('/put', stream=True)
|
||||||
async def put(request):
|
async def put(request):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
|
|
||||||
async def streaming(response):
|
async def streaming(response):
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
await response.write(body.decode('utf-8'))
|
await response.write(body.decode('utf-8'))
|
||||||
|
@ -105,11 +107,11 @@ def test_request_stream_app(app):
|
||||||
|
|
||||||
@app.patch('/patch', stream=True)
|
@app.patch('/patch', stream=True)
|
||||||
async def patch(request):
|
async def patch(request):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
|
|
||||||
async def streaming(response):
|
async def streaming(response):
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
await response.write(body.decode('utf-8'))
|
await response.write(body.decode('utf-8'))
|
||||||
|
@ -163,11 +165,11 @@ def test_request_stream_handle_exception(app):
|
||||||
|
|
||||||
@app.post('/post/<id>', stream=True)
|
@app.post('/post/<id>', stream=True)
|
||||||
async def post(request, id):
|
async def post(request, id):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
|
|
||||||
async def streaming(response):
|
async def streaming(response):
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
await response.write(body.decode('utf-8'))
|
await response.write(body.decode('utf-8'))
|
||||||
|
@ -216,11 +218,11 @@ def test_request_stream_blueprint(app):
|
||||||
|
|
||||||
@bp.post('/post/<id>', stream=True)
|
@bp.post('/post/<id>', stream=True)
|
||||||
async def post(request, id):
|
async def post(request, id):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
|
|
||||||
async def streaming(response):
|
async def streaming(response):
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
await response.write(body.decode('utf-8'))
|
await response.write(body.decode('utf-8'))
|
||||||
|
@ -233,11 +235,11 @@ def test_request_stream_blueprint(app):
|
||||||
|
|
||||||
@bp.put('/put', stream=True)
|
@bp.put('/put', stream=True)
|
||||||
async def put(request):
|
async def put(request):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
|
|
||||||
async def streaming(response):
|
async def streaming(response):
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
await response.write(body.decode('utf-8'))
|
await response.write(body.decode('utf-8'))
|
||||||
|
@ -250,11 +252,11 @@ def test_request_stream_blueprint(app):
|
||||||
|
|
||||||
@bp.patch('/patch', stream=True)
|
@bp.patch('/patch', stream=True)
|
||||||
async def patch(request):
|
async def patch(request):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
|
|
||||||
async def streaming(response):
|
async def streaming(response):
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
await response.write(body.decode('utf-8'))
|
await response.write(body.decode('utf-8'))
|
||||||
|
@ -313,10 +315,10 @@ def test_request_stream_composition_view(app):
|
||||||
return text('OK')
|
return text('OK')
|
||||||
|
|
||||||
async def post_handler(request):
|
async def post_handler(request):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
result = ''
|
result = ''
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
result += body.decode('utf-8')
|
result += body.decode('utf-8')
|
||||||
|
@ -350,10 +352,10 @@ def test_request_stream(app):
|
||||||
|
|
||||||
@stream_decorator
|
@stream_decorator
|
||||||
async def post(self, request):
|
async def post(self, request):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
result = ''
|
result = ''
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
result += body.decode('utf-8')
|
result += body.decode('utf-8')
|
||||||
|
@ -361,11 +363,11 @@ def test_request_stream(app):
|
||||||
|
|
||||||
@app.post('/stream', stream=True)
|
@app.post('/stream', stream=True)
|
||||||
async def handler(request):
|
async def handler(request):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
|
|
||||||
async def streaming(response):
|
async def streaming(response):
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
await response.write(body.decode('utf-8'))
|
await response.write(body.decode('utf-8'))
|
||||||
|
@ -378,10 +380,10 @@ def test_request_stream(app):
|
||||||
|
|
||||||
@bp.post('/bp_stream', stream=True)
|
@bp.post('/bp_stream', stream=True)
|
||||||
async def bp_stream(request):
|
async def bp_stream(request):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
result = ''
|
result = ''
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
result += body.decode('utf-8')
|
result += body.decode('utf-8')
|
||||||
|
@ -397,10 +399,10 @@ def test_request_stream(app):
|
||||||
return text('OK')
|
return text('OK')
|
||||||
|
|
||||||
async def post_handler(request):
|
async def post_handler(request):
|
||||||
assert isinstance(request.stream, asyncio.Queue)
|
assert isinstance(request.stream, StreamBuffer)
|
||||||
result = ''
|
result = ''
|
||||||
while True:
|
while True:
|
||||||
body = await request.stream.get()
|
body = await request.stream.read()
|
||||||
if body is None:
|
if body is None:
|
||||||
break
|
break
|
||||||
result += body.decode('utf-8')
|
result += body.decode('utf-8')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user