11import pytest
2+ from packaging import version
23from http import HTTPStatus
34from quart_openapi import Pint , Resource , PintBlueprint
45from quart import Blueprint , url_for , request , ResponseReturnValue , abort
6+ from quart .__about__ import __version__ as quart_version
57from quart .views import MethodView
68
9+ QUART_VER_GT_09 = version .parse (quart_version ) >= version .parse ('0.9.0' )
10+
11+ def req_ctx (app : Pint , page : str , method : str = '' ):
12+ if QUART_VER_GT_09 :
13+ return app .test_request_context (page , method = method )
14+ else :
15+ return app .test_request_context (method , page )
16+
717@pytest .mark .asyncio
818async def test_root_endpoint_blueprint (app : Pint ) -> None :
919 blueprint = Blueprint ('blueprint' , __name__ )
@@ -13,7 +23,7 @@ async def route() -> ResponseReturnValue:
1323 return 'OK'
1424
1525 app .register_blueprint (blueprint )
16- async with app . test_request_context ( 'GET' , '/page/' ):
26+ async with req_ctx ( app , '/page/' , method = 'GET ' ):
1727 assert request .blueprint == 'blueprint'
1828 assert '/page/' == url_for ('blueprint.route' )
1929
@@ -31,18 +41,18 @@ async def route() -> ResponseReturnValue:
3141 app .register_blueprint (blueprint , url_prefix = '/blueprint' )
3242 app .register_blueprint (prefix )
3343
34- async with app . test_request_context ( 'GET ' , '/ ' ):
44+ async with req_ctx ( app , '/ ' , method = 'GET ' ):
3545 assert '/page/' == url_for ('route' )
3646 assert '/prefix/page/' == url_for ('prefix.route' )
3747 assert '/blueprint/page/' == url_for ('blueprint.route' )
3848
39- async with app . test_request_context ( 'GET' , '/page/' ):
49+ async with req_ctx ( app , '/page/' , method = 'GET ' ):
4050 assert request .blueprint is None
4151
42- async with app . test_request_context ( 'GET' , '/prefix/page/' ):
52+ async with req_ctx ( app , '/prefix/page/' , method = 'GET ' ):
4353 assert request .blueprint == 'prefix'
4454
45- async with app . test_request_context ( 'GET' , '/blueprint/page/' ):
55+ async with req_ctx ( app , '/blueprint/page/' , method = 'GET ' ):
4656 assert request .blueprint == 'blueprint'
4757
4858
@@ -90,7 +100,7 @@ async def test_pint_blueprint_openapi(app: Pint) -> None:
90100 blueprint = PintBlueprint ('blueprint' , __name__ , url_prefix = '/blueprint' )
91101 app .register_blueprint (blueprint )
92102
93- async with app . test_request_context ( 'GET ' , '/ ' ):
103+ async with req_ctx ( app , '/ ' , method = 'GET ' ):
94104 assert '/openapi.json' == url_for ('openapi' )
95105
96106
0 commit comments