Reuse app fixture in tests
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import asyncio
|
||||
from sanic import Sanic
|
||||
from sanic.blueprints import Blueprint
|
||||
from sanic.views import CompositionView
|
||||
from sanic.views import HTTPMethodView
|
||||
@@ -9,11 +8,9 @@ from sanic.response import stream, text
|
||||
data = "abc" * 100000
|
||||
|
||||
|
||||
def test_request_stream_method_view():
|
||||
def test_request_stream_method_view(app):
|
||||
'''for self.is_request_stream = True'''
|
||||
|
||||
app = Sanic('test_request_stream_method_view')
|
||||
|
||||
class SimpleView(HTTPMethodView):
|
||||
|
||||
def get(self, request):
|
||||
@@ -44,11 +41,9 @@ def test_request_stream_method_view():
|
||||
assert response.text == data
|
||||
|
||||
|
||||
def test_request_stream_app():
|
||||
def test_request_stream_app(app):
|
||||
'''for self.is_request_stream = True and decorators'''
|
||||
|
||||
app = Sanic('test_request_stream_app')
|
||||
|
||||
@app.get('/get')
|
||||
async def get(request):
|
||||
assert request.stream is None
|
||||
@@ -163,11 +158,9 @@ def test_request_stream_app():
|
||||
assert response.text == data
|
||||
|
||||
|
||||
def test_request_stream_handle_exception():
|
||||
def test_request_stream_handle_exception(app):
|
||||
'''for handling exceptions properly'''
|
||||
|
||||
app = Sanic('test_request_stream_exception')
|
||||
|
||||
@app.post('/post/<id>', stream=True)
|
||||
async def post(request, id):
|
||||
assert isinstance(request.stream, asyncio.Queue)
|
||||
@@ -191,10 +184,8 @@ def test_request_stream_handle_exception():
|
||||
assert response.text == 'Error: Method GET not allowed for URL /post/random_id'
|
||||
|
||||
|
||||
def test_request_stream_blueprint():
|
||||
def test_request_stream_blueprint(app):
|
||||
'''for self.is_request_stream = True'''
|
||||
|
||||
app = Sanic('test_request_stream_blueprint')
|
||||
bp = Blueprint('test_blueprint_request_stream_blueprint')
|
||||
|
||||
@app.get('/get')
|
||||
@@ -313,11 +304,9 @@ def test_request_stream_blueprint():
|
||||
assert response.text == data
|
||||
|
||||
|
||||
def test_request_stream_composition_view():
|
||||
def test_request_stream_composition_view(app):
|
||||
'''for self.is_request_stream = True'''
|
||||
|
||||
app = Sanic('test_request_stream__composition_view')
|
||||
|
||||
def get_handler(request):
|
||||
assert request.stream is None
|
||||
return text('OK')
|
||||
@@ -348,11 +337,9 @@ def test_request_stream_composition_view():
|
||||
assert response.text == data
|
||||
|
||||
|
||||
def test_request_stream():
|
||||
def test_request_stream(app):
|
||||
'''test for complex application'''
|
||||
|
||||
bp = Blueprint('test_blueprint_request_stream')
|
||||
app = Sanic('test_request_stream')
|
||||
|
||||
class SimpleView(HTTPMethodView):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user