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


Python test_utils.TestClient方法代码示例

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


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

示例1: test_client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [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

示例2: test_get_post

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [as 别名]
def test_get_post(client: _TestClient, db: aiosqlite.Connection) -> None:
    async with db.execute(
        "INSERT INTO posts (title, text, owner, editor) VALUES (?, ?, ?, ?)",
        ["title", "text", "user", "user"],
    ) as cursor:
        post_id = cursor.lastrowid
    await db.commit()

    resp = await client.get(f"/api/{post_id}")
    assert resp.status == 200
    data = await resp.json()
    assert data == {
        "data": {
            "editor": "user",
            "id": "1",
            "owner": "user",
            "text": "text",
            "title": "title",
        },
        "status": "ok",
    } 
开发者ID:asvetlov,项目名称:us-pycon-2019-tutorial,代码行数:23,代码来源:test_rest.py

示例3: client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [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 TestClient [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 TestClient [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 TestClient [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 TestClient [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: client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [as 别名]
def client(aiohttp_client, server) -> TestClient:
    return await aiohttp_client(server) 
开发者ID:aalhour,项目名称:cookiecutter-aiohttp-sqlalchemy,代码行数:4,代码来源:conftest.py

示例9: xtest_render_html_basic

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [as 别名]
def xtest_render_html_basic(event_loop):
    expected = BS(open(os.path.join(RESPONSES_DIR, 'httpbin.org.html.txt')).read()).prettify()
    client = tc(setup_app(loop=event_loop), loop=event_loop)
    await client.start_server()
    resp = await client.get('/render.html?url={}'.format(quote('{}/html'.format(HTTPBIN_HOST))))
    assert resp.status == 200
    text = await resp.text()
    assert expected == text 
开发者ID:chuckus,项目名称:chromewhip,代码行数:10,代码来源:test_chromewhip.py

示例10: xtest_render_html_with_js_profile

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [as 别名]
def xtest_render_html_with_js_profile(event_loop):
    expected = BS(open(os.path.join(RESPONSES_DIR, 'httpbin.org.html.after_profile.txt')).read()).prettify()
    profile_name = 'httpbin-org-html'
    profile_path = os.path.join(PROJECT_ROOT, 'tests/resources/js/profiles/{}'.format(profile_name))
    client = tc(setup_app(loop=event_loop, js_profiles_path=profile_path), loop=event_loop)
    await client.start_server()
    resp = await client.get('/render.html?url={}&js={}'.format(
        quote('{}/html'.format(HTTPBIN_HOST)),
        profile_name))
    assert resp.status == 200
    text = await resp.text()
    assert expected == text 
开发者ID:chuckus,项目名称:chromewhip,代码行数:14,代码来源:test_chromewhip.py

示例11: aiohttp_client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [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

示例12: http_client

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [as 别名]
def http_client(http_server):
    client = TestClient(http_server)
    asyncio.ensure_future(client.start_server())
    await asyncio.sleep(0.01)
    return client 
开发者ID:ethereum,项目名称:trinity,代码行数:7,代码来源:test_api_server.py

示例13: test_client_is_passed_to_test

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [as 别名]
def test_client_is_passed_to_test(self):
        @http_client(self.app)
        async def my_test_case(client):
            return client

        client = await my_test_case()
        self.assertTrue(isinstance(client, TestClient)) 
开发者ID:b2wdigital,项目名称:async-worker,代码行数:9,代码来源:test_test_utils.py

示例14: test_decorated_method_can_have_its_own_params

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [as 别名]
def test_decorated_method_can_have_its_own_params(self):
        @http_client(self.app)
        async def my_method(a, b, http_client):
            return (http_client, a, b)

        rv = await my_method(42, 10)

        self.assertTrue(isinstance(rv[0], TestClient))
        self.assertEqual([42, 10], [rv[1], rv[2]]) 
开发者ID:b2wdigital,项目名称:async-worker,代码行数:11,代码来源:test_test_utils.py

示例15: _get_client_and_server

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import TestClient [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


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