当前位置: 首页>>代码示例>>Python>>正文


Python test_utils.TestServer方法代码示例

本文整理汇总了Python中aiohttp.test_utils.TestServer方法的典型用法代码示例。如果您正苦于以下问题:Python test_utils.TestServer方法的具体用法?Python test_utils.TestServer怎么用?Python test_utils.TestServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiohttp.test_utils的用法示例。


在下文中一共展示了test_utils.TestServer方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: aiohttp_server

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def aiohttp_server():
    """Factory to create a TestServer instance, given an app.

    aiohttp_server(app, **kwargs)
    """
    servers = []

    async def go(app, *, port=None, **kwargs):  # type: ignore
        server = AIOHTTPTestServer(app, port=port)
        await server.start_server(**kwargs)
        servers.append(server)
        return server

    yield go

    while servers:
        await servers.pop().close()


# Adding debug logs to websocket tests 
开发者ID:graphql-python,项目名称:gql,代码行数:22,代码来源:conftest.py

示例2: test_client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def test_client(loop, client_class):
    """Factory to create a TestClient instance.
    test_client(app, **kwargs)
    """
    clients = []

    async def go(app, server_kwargs=None, **kwargs):
        if isinstance(app, web.Application):
            server_kwargs = server_kwargs or {}
            server = test_utils.TestServer(app, loop=loop, **server_kwargs)
        else:
            server = app
        client = client_class(server, loop=loop, **kwargs)
        await client.start_server()
        clients.append(client)
        return client

    yield go

    async def finalize():
        while clients:
            await clients.pop().close()

    loop.run_until_complete(finalize()) 
开发者ID:dvhb,项目名称:dvhb-hybrid,代码行数:26,代码来源:tests.py

示例3: client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def client(app):
    client = TestClient(TestServer(app))
    await client.start_server()
    yield client
    await client.close() 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:7,代码来源:test_graphiqlview.py

示例4: working_client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def working_client():
    loop = asyncio.get_event_loop()

    app = web.Application()

    app.router.add_get('/.well-known/openid-configuration', respond_json({'token_endpoint': '/token'}))
    app.router.add_post('/token', respond_json({'id-token': 'id-token-data', 'refresh-token': 'refresh-token-data'}))

    with patch('kubernetes_asyncio.config.openid.aiohttp.ClientSession') as _client_session:
        client = _TestClient(_TestServer(app, loop=loop), loop=loop)
        _client_session.return_value = client

        yield client 
开发者ID:tomplus,项目名称:kubernetes_asyncio,代码行数:15,代码来源:openid_test.py

示例5: fail_well_known_client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def fail_well_known_client():
    loop = asyncio.get_event_loop()
    app = web.Application()

    app.router.add_get('/.well-known/openid-configuration', make_responder(web.Response(status=500)))

    with patch('kubernetes_asyncio.config.openid.aiohttp.ClientSession') as _client_session:
        client = _TestClient(_TestServer(app, loop=loop), loop=loop)
        _client_session.return_value = client
        yield client 
开发者ID:tomplus,项目名称:kubernetes_asyncio,代码行数:12,代码来源:openid_test.py

示例6: fail_token_request_client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def fail_token_request_client():
    loop = asyncio.get_event_loop()
    app = web.Application()

    app.router.add_get('/.well-known/openid-configuration', respond_json({'token_endpoint': '/token'}))
    app.router.add_post('/token', make_responder(web.Response(status=500)))

    with patch('kubernetes_asyncio.config.openid.aiohttp.ClientSession') as _client_session:
        client = _TestClient(_TestServer(app, loop=loop), loop=loop)
        _client_session.return_value = client

        yield client 
开发者ID:tomplus,项目名称:kubernetes_asyncio,代码行数:14,代码来源:openid_test.py

示例7: test_rpc_client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def test_rpc_client(loop):
    test_client = None
    rpc_client = None

    async def _create_from_app_factory(app_factory, *args, **kwargs):
        nonlocal test_client, rpc_client
        app = app_factory(loop, *args, **kwargs)
        test_client = TestClient(TestServer(app), loop=loop)
        await test_client.start_server()

        rpc_client = ServerProxy(
            '',
            loop=loop,
            client=test_client
        )
        return rpc_client

    yield _create_from_app_factory

    if rpc_client:
        loop.run_until_complete(rpc_client.close())
        rpc_client = None

    if test_client:
        loop.run_until_complete(test_client.close())
        test_client = None 
开发者ID:mosquito,项目名称:aiohttp-xmlrpc,代码行数:28,代码来源:pytest_plugin.py

示例8: server

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def server(aiohttp_server) -> TestServer:
    app = create_app()
    server = await aiohttp_server(app, port=TEST_PORT)
    return server 
开发者ID:aalhour,项目名称:cookiecutter-aiohttp-sqlalchemy,代码行数:6,代码来源:conftest.py

示例9: aiohttp_client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def aiohttp_client(self, app: asyncworker.App) -> TestClient:
        routes = app.routes_registry.http_routes
        http_app = web.Application()

        for route in routes:
            for route_def in route.aiohttp_routes():
                route_def.register(http_app.router)

        self.server = TestServer(
            http_app, port=int(os.getenv("TEST_ASYNCWORKER_HTTP_PORT") or 0)
        )
        client = TestClient(self.server)
        await self.server.start_server()

        return client 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:17,代码来源:util.py

示例10: fake_zipkin

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def fake_zipkin(loop):
    zipkin = FakeZipkin(loop=loop)

    server = TestServer(zipkin.app, loop=loop)
    await server.start_server()
    zipkin.port = server.port

    await yield_(zipkin)

    await server.close() 
开发者ID:aio-libs,项目名称:aiozipkin,代码行数:12,代码来源:conftest.py

示例11: _get_client_and_server

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def _get_client_and_server(app: App) -> Tuple[TestClient, TestServer]:
    routes = app.routes_registry.http_routes
    http_app = web.Application()

    for route in routes:
        for route_def in route.aiohttp_routes():
            route_def.register(http_app.router)

    port = int(os.getenv("TEST_ASYNCWORKER_HTTP_PORT") or 0)
    server = TestServer(http_app, port=port)
    client = TestClient(server)
    await server.start_server()
    return (client, server) 
开发者ID:b2wdigital,项目名称:async-worker,代码行数:15,代码来源:__init__.py

示例12: server

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def server(aiohttp_server: Any, db_path: Path) -> _TestServer:
    app = await init_app(db_path)
    return await aiohttp_server(app) 
开发者ID:asvetlov,项目名称:us-pycon-2019-tutorial,代码行数:5,代码来源:test_client.py

示例13: client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def client(server: _TestServer) -> AsyncIterator[Client]:
    async with Client(server.make_url("/"), "test_user") as client:
        yield client 
开发者ID:asvetlov,项目名称:us-pycon-2019-tutorial,代码行数:5,代码来源:test_client.py

示例14: fake_cloud

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestServer [as 别名]
def fake_cloud(aiohttp_server, ssl_ctx):
    """Defines the testserver funcarg"""

    loop = asyncio.new_event_loop()
    stop_threads = False
    t = Thread(
        name="aio_fake_cloud",
        target=start_background_loop,
        args=(lambda: stop_threads, loop),
    )
    t.setDaemon(True)
    t.start()

    aio_server = AsyncFakeCloudServer()
    app = web.Application()
    app.router.add_route("GET", "/{tail:.*}", aio_server)
    app.router.add_route("POST", "/{tail:.*}", aio_server)

    server = TestServer(app)
    asyncio.run_coroutine_threadsafe(
        server.start_server(loop=loop, ssl=ssl_ctx), loop
    ).result()
    aio_server.url = str(server._root)
    server.url = aio_server.url

    yield server

    asyncio.run_coroutine_threadsafe(server.close(), loop).result()
    stop_threads = True 
开发者ID:coreGreenberet,项目名称:homematicip-rest-api,代码行数:31,代码来源:conftest.py


注:本文中的aiohttp.test_utils.TestServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。