async def test_blueprint_url_prefix(app: Pint) -> None:
    blueprint = Blueprint('blueprint', __name__)
    prefix = Blueprint('prefix', __name__, url_prefix='/prefix')

    @app.route('/page/')
    @blueprint.route('/page/')
    @prefix.route('/page/')
    async def route() -> ResponseReturnValue:
        return 'OK'

    app.register_blueprint(blueprint, url_prefix='/blueprint')
    app.register_blueprint(prefix)

    async with app.test_request_context('GET', '/'):
        assert '/page/' == url_for('route')
        assert '/prefix/page/' == url_for('prefix.route')
        assert '/blueprint/page/' == url_for('blueprint.route')

    async with app.test_request_context('GET', '/page/'):
        assert request.blueprint is None

    async with app.test_request_context('GET', '/prefix/page/'):
        assert request.blueprint == 'prefix'

    async with app.test_request_context('GET', '/blueprint/page/'):
        assert request.blueprint == 'blueprint'
async def test_root_endpoint_blueprint(app: Pint) -> None:
    blueprint = Blueprint('blueprint', __name__)

    @blueprint.route('/page/')
    async def route() -> ResponseReturnValue:
        return 'OK'

    app.register_blueprint(blueprint)
    async with app.test_request_context('GET', '/page/'):
        assert request.blueprint == 'blueprint'
        assert '/page/' == url_for('blueprint.route')
Пример #3
0
def req_ctx(app: Pint, page: str, method: str = ''):
    if QUART_VER_GT_09:
        return app.test_request_context(page, method=method)
    else:
        return app.test_request_context(method, page)
Пример #4
0
 def func(testapp: Pint, page: str, method: str = ''):
     if QUART_VER_GT_09:
         return testapp.test_request_context(page, method=method)
     return testapp.test_request_context(method, page)
async def test_pint_blueprint_openapi(app: Pint) -> None:
    blueprint = PintBlueprint('blueprint', __name__, url_prefix='/blueprint')
    app.register_blueprint(blueprint)

    async with app.test_request_context('GET', '/'):
        assert '/openapi.json' == url_for('openapi')