Exemplo n.º 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 = {}
Exemplo n.º 2
0
 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
Exemplo n.º 3
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()
Exemplo n.º 4
0
    async def go(app, server_kwargs=None, **kwargs):  # type: ignore
        server_kwargs = server_kwargs or {}

        server = test_utils.TestServer(app, loop=loop, **server_kwargs)
        client = TestClient(
            server,
            basic_auth=("a", "b"),
            response_cls=kwargs.pop("response_cls", Response),
        )
        session = client.get_session(loop=loop, **kwargs)

        await session.start_server()
        sessions.append(session)
        return server, client, session
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 8
0
    async def handle_request(self,
                             method: str,
                             path: str,
                             resp: aiohttp.web.Response = None,
                             ) -> client.Model:
        resp = aiohttp.web.Response() if resp is None else resp
        handler_mock = asynctest.AsyncMagicMock(return_value=resp)

        app = aiohttp.web.Application()
        route = aiohttp.web.RouteDef(
            method, path, asynctest.unittest_handler(handler_mock), {})

        app.add_routes([route])

        async with aiohttptest.TestServer(app) as server:
            service_url = str(server.make_url(""))
            yield client.Model(client.Session(service_url))

        handler_mock.assert_called()
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
Exemplo n.º 10
0
 def test_client(self) -> test_utils.TestClient:
     return test_utils.TestClient(test_utils.TestServer(self.get_app()),
                                  loop=asyncio.get_event_loop())
Exemplo n.º 11
0
 async def get_server(self, app: Application) -> aiohttptest.TestServer:
     return aiohttptest.TestServer(
         app,
         loop=self.loop,
         ssl=self.server_ssl_context,
     )
Exemplo n.º 12
0
 def __init__(self, config, mock_username=None):
     self.server = test_utils.TestServer(mock_auth_app())
Exemplo n.º 13
0
async def client(app):
    async with test_utils.TestClient(test_utils.TestServer(app)) as client:
        yield client
Exemplo n.º 14
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