Ejemplo n.º 1
0
async def test_has_request_context() -> None:
    async with RequestContext(Quart(__name__),
                              Request('GET', 'http', '/', CIMultiDict())):
        assert has_request_context() is True
        assert has_app_context() is True
    assert has_request_context() is False
    assert has_app_context() is False
Ejemplo n.º 2
0
async def test_has_request_context() -> None:
    app = Quart(__name__)
    headers, path, query_string = make_test_headers_path_and_query_string(app, '/')
    async with RequestContext(Quart(__name__), Request('GET', 'http', path, query_string, headers)):
        assert has_request_context() is True
        assert has_app_context() is True
    assert has_request_context() is False
    assert has_app_context() is False
Ejemplo n.º 3
0
async def test_has_request_context() -> None:
    app = Quart(__name__)
    headers, path, query_string = make_test_headers_path_and_query_string(app, "/")
    request = Request(
        "GET", "http", path, query_string, headers, "", "1.1", send_push_promise=no_op_push
    )
    async with RequestContext(Quart(__name__), request):
        assert has_request_context() is True
        assert has_app_context() is True
    assert has_request_context() is False
    assert has_app_context() is False
Ejemplo n.º 4
0
async def test_overlapping_websocket_ctx(
        websocket_scope: WebsocketScope) -> None:
    app = Quart(__name__)

    websocket = Websocket(
        "/",
        b"",
        "ws",
        Headers([("host", "quart.com")]),
        "",
        "1.1",
        [],
        None,
        None,
        None,
        None,
        websocket_scope,
    )
    ctx1 = app.websocket_context(websocket)
    await ctx1.__aenter__()
    ctx2 = app.websocket_context(websocket)
    await ctx2.__aenter__()
    await ctx1.__aexit__(None, None, None)
    assert has_app_context()  # Ensure the app context still exists for ctx2
    await ctx2.__aexit__(None, None, None)
Ejemplo n.º 5
0
async def test_overlapping_websocket_ctx() -> None:
    app = Quart(__name__)

    websocket = Websocket("/", b"", "ws", CIMultiDict(), "", "1.1", [], None, None, None)
    ctx1 = app.websocket_context(websocket)
    await ctx1.__aenter__()
    ctx2 = app.websocket_context(websocket)
    await ctx2.__aenter__()
    await ctx1.__aexit__(None, None, None)
    assert has_app_context()  # Ensure the app context still exists for ctx2
    await ctx2.__aexit__(None, None, None)
Ejemplo n.º 6
0
async def test_overlapping_request_ctx() -> None:
    app = Quart(__name__)

    request = Request('GET', 'http', '/', b'', CIMultiDict())
    ctx1 = app.request_context(request)
    await ctx1.__aenter__()
    ctx2 = app.request_context(request)
    await ctx2.__aenter__()
    await ctx1.__aexit__(None, None, None)
    assert has_app_context()  # Ensure the app context still exists for ctx2
    await ctx2.__aexit__(None, None, None)
Ejemplo n.º 7
0
async def test_overlapping_request_ctx() -> None:
    app = Quart(__name__)

    request = Request(
        "GET", "http", "/", b"", CIMultiDict(), "", "1.1", send_push_promise=no_op_push
    )
    ctx1 = app.request_context(request)
    await ctx1.__aenter__()
    ctx2 = app.request_context(request)
    await ctx2.__aenter__()
    await ctx1.__aexit__(None, None, None)
    assert has_app_context()  # Ensure the app context still exists for ctx2
    await ctx2.__aexit__(None, None, None)
Ejemplo n.º 8
0
async def test_overlapping_request_ctx(http_scope: HTTPScope) -> None:
    app = Quart(__name__)

    request = Request(
        "GET",
        "http",
        "/",
        b"",
        Headers([("host", "quart.com")]),
        "",
        "1.1",
        http_scope,
        send_push_promise=no_op_push,
    )
    ctx1 = app.request_context(request)
    await ctx1.__aenter__()
    ctx2 = app.request_context(request)
    await ctx2.__aenter__()
    await ctx1.__aexit__(None, None, None)
    assert has_app_context()  # Ensure the app context still exists for ctx2
    await ctx2.__aexit__(None, None, None)
Ejemplo n.º 9
0
async def test_has_app_context() -> None:
    async with AppContext(Quart(__name__)):
        assert has_app_context() is True
    assert has_app_context() is False