示例#1
0
 def __init__(self, context: BolinetteContext, loop: AbstractEventLoop):
     abc.WithContext.__init__(self, context)
     WithDataContext.__init__(self, context.registry.get(DataContext))
     server = test_utils.TestServer(context.registry.get(Application),
                                    loop=loop)
     self.client = test_utils.TestClient(server, loop=loop)
     self.mock = Mock(context)
     self.cookies = {}
示例#2
0
async def proxy_server_mock(server_port, loop):
    app = aiohttp.web.Application()
    app['calls'] = []
    app.router.add_route('post', '/', proxy_server_handler_mock)

    server = test_utils.TestServer(app, port=server_port)
    client = test_utils.TestClient(server)
    await server.start_server(loop)
    try:
        yield app
    finally:
        await client.close()
        await server.close()
示例#3
0
async def jaeger_mock_server(jaeger_port):
    app = WaitingApp()

    app.router.add_route("POST", "/api/traces", handler)

    server = test_utils.TestServer(app, port=jaeger_port)
    client = test_utils.TestClient(server)

    await client.start_server()
    try:
        yield app
    finally:
        await client.close()
        await server.close()
示例#4
0
async def client(loop, aiohttp_app):
    aiohttp_app.router.add_route("GET", "/data", get_data)

    aiohttp_app.middlewares.append(compress_middleware)

    test_server = test_utils.TestServer(aiohttp_app, port=8090)
    test_client = test_utils.TestClient(test_server)

    await test_client.start_server()

    try:
        yield test_client
    finally:
        await test_server.close()
        await test_client.close()
async def client(loop, asgi_resource, aiohttp_app):
    aiohttp_app.router.register_resource(asgi_resource)

    asgi_resource.lifespan_mount(
        aiohttp_app,
        startup=True,
        shutdown=True,
    )

    test_server = test_utils.TestServer(aiohttp_app)
    test_client = test_utils.TestClient(test_server)

    await test_client.start_server()

    try:
        yield test_client
    finally:
        await test_server.close()
        await test_client.close()
async def test_normalize_path_middleware(asgi_resource, middlewares):
    aiohttp_app = web.Application(middlewares=middlewares)
    aiohttp_app.router.register_resource(asgi_resource)
    asgi_resource.lifespan_mount(
        aiohttp_app,
        startup=True,
        shutdown=True,
    )

    async with test_utils.TestServer(aiohttp_app) as test_server:
        async with test_utils.TestClient(test_server) as client:
            async with client.get("/asgi") as response:
                response.raise_for_status()
                body = await response.json()

            assert body == {'message': 'Hello World', 'root_path': ''}

            async with client.get("/not-found") as response:
                with pytest.raises(aiohttp.ClientError) as err:
                    response.raise_for_status()

            assert err.value.status == 404
示例#7
0
文件: utils.py 项目: andvikt/megad2
 def test_client(self) -> test_utils.TestClient:
     return test_utils.TestClient(test_utils.TestServer(self.get_app()),
                                  loop=asyncio.get_event_loop())
示例#8
0
文件: conftest.py 项目: rbw/aiosnow
 def get_session(self, *args, **kwargs):
     return test_utils.TestClient(self._server,
                                  *args,
                                  response_class=self.response_cls,
                                  **kwargs)
示例#9
0
 async def __aenter__(self):
     await self.server.start_server(loop=asyncio.get_event_loop())
     self.client = test_utils.TestClient(self.server, loop=asyncio.get_event_loop())
     return self.client
示例#10
0
async def client(app):
    async with test_utils.TestClient(test_utils.TestServer(app)) as client:
        yield client
示例#11
0
 def session_maker(_):
     return test_utils.TestClient(
         api.server,
         loop=loop,
         headers=librarian.github.GitHub.make_default_headers(
             gh_token)).session
示例#12
0
async def cli(mocker):
    mocker.patch('application.app.setup_rabbit', new=setup_rabbit_mock)
    application = app.create_app()

    async with test_utils.TestClient(test_utils.TestServer(application)) as client:
        yield client