Add async view tests.
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com> Co-authored-by: Kevin Yang <kkaiyang94@users.noreply.github.com> Co-authored-by: Katherine Kelly <kat-star@users.noreply.github.com>
This commit is contained in:
parent
01c56e0947
commit
223e686266
1 changed files with 19 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ import pytest
|
|||
from flask import Blueprint
|
||||
from flask import Flask
|
||||
from flask import request
|
||||
from flask.views import View, MethodView
|
||||
|
||||
pytest.importorskip("asgiref")
|
||||
|
||||
|
|
@ -53,11 +54,28 @@ def _async_app():
|
|||
|
||||
app.register_blueprint(blueprint, url_prefix="/bp")
|
||||
|
||||
class AsyncView(View):
|
||||
methods = ["GET", "POST"]
|
||||
|
||||
async def dispatch_request(self):
|
||||
return request.method
|
||||
|
||||
app.add_url_rule("/async_view", view_func=AsyncView.as_view("async_view"))
|
||||
|
||||
class AsyncMethodView(MethodView):
|
||||
async def get(self):
|
||||
return "GET"
|
||||
|
||||
async def post(self):
|
||||
return "POST"
|
||||
|
||||
app.add_url_rule("/async_methodview", view_func=AsyncMethodView.as_view("async_methodview"))
|
||||
|
||||
return app
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")
|
||||
@pytest.mark.parametrize("path", ["/", "/home", "/bp/"])
|
||||
@pytest.mark.parametrize("path", ["/", "/home", "/bp/", "async_view", "async_methodview"])
|
||||
def test_async_route(path, async_app):
|
||||
test_client = async_app.test_client()
|
||||
response = test_client.get(path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue