Exemplo n.º 1
0
def test_client_unsupported_arg() -> None:
    with pytest.raises(TypeError) as e:
        _TestClient("string")

    assert (
        str(e.value) == "server must be TestServer instance, found type: <class 'str'>"
    )
Exemplo n.º 2
0
async def test_client_context_manager_response(method, app, loop):
    async with _TestClient(_TestServer(app), loop=loop) as client:
        async with getattr(client, method)('/') as resp:
            assert resp.status == 200
            if method != 'head':
                text = await resp.text()
                assert "Hello, world" in text
Exemplo n.º 3
0
async def test_aiohttp_client_close_is_idempotent() -> None:
    # a test client, called multiple times, should
    # not attempt to close the server again.
    app = _create_example_app()
    client = _TestClient(_TestServer(app))
    await client.close()
    await client.close()
def function1698():
    '\n    a test client, called multiple times, should\n    not attempt to close the server again.\n    '
    var1555 = setup_test_loop()
    var2252 = function2617()
    var65 = _TestClient(var2252, loop=var1555)
    var1555.run_until_complete(var65.close())
    var1555.run_until_complete(var65.close())
    teardown_test_loop(var1555)
Exemplo n.º 5
0
async def test_client_context_manager_response(method: Any, app: Any,
                                               loop: Any) -> None:
    async with _TestClient(_TestServer(app)) as client:
        async with getattr(client, method)("/") as resp:
            assert resp.status == 200
            if method != "head":
                text = await resp.text()
                assert "Hello, world" in text
def function424(function1993):
    function4 = function2617()
    var2021 = _TestClient(function4, loop=function1993, host='localhost')
    assert (var2021.host == 'localhost')
    assert (var2021.port is None)
    with client:
        assert isinstance(var2021.port, int)
        assert (var2021.server is not None)
    assert (var2021.port is None)
    def _get_client(self, app_or_server):
        """Return a TestClient instance."""
        client_constructor_arg = app_or_server

        scheme = "http"
        host = "127.0.0.1"
        server_kwargs = {}
        if self.server_cls:
            test_server = self.server_cls(app_or_server,
                                          scheme=scheme,
                                          host=host,
                                          **server_kwargs)
            client_constructor_arg = test_server

        try:
            return _TestClient(client_constructor_arg, loop=self.loop)
        except TypeError:
            return _TestClient(client_constructor_arg)
Exemplo n.º 8
0
def test_test_client_props(loop):
    app = _create_example_app()
    client = _TestClient(app, loop=loop, host='localhost')
    assert client.host == 'localhost'
    assert client.port is None
    with client:
        assert isinstance(client.port, int)
        assert client.server is not None
    assert client.port is None
Exemplo n.º 9
0
async def test_aiohttp_client_close_is_idempotent() -> None:
    """
    a test client, called multiple times, should
    not attempt to close the server again.
    """
    app = _create_example_app()
    client = _TestClient(_TestServer(app))
    await client.close()
    await client.close()
Exemplo n.º 10
0
def test_test_client_props(loop):
    app = _create_example_app(loop)
    client = _TestClient(app, host='localhost')
    assert client.host == 'localhost'
    assert client.port is None
    with client:
        assert isinstance(client.port, int)
        assert client.server is not None
    assert client.port is None
async def test_test_client_props(loop):
    app = _create_example_app()
    client = _TestClient(_TestServer(app, host='127.0.0.1', loop=loop),
                         loop=loop)
    assert client.host == '127.0.0.1'
    assert client.port is None
    async with client:
        assert isinstance(client.port, int)
        assert client.server is not None
    assert client.port is None
Exemplo n.º 12
0
def test_test_client_close_is_idempotent():
    """
    a test client, called multiple times, should
    not attempt to close the loop again.
    """
    loop = setup_test_loop()
    app = _create_example_app(loop)
    client = _TestClient(app)
    client.close()
    teardown_test_loop(loop)
    client.close()
Exemplo n.º 13
0
def test_aiohttp_client_close_is_idempotent():
    """
    a test client, called multiple times, should
    not attempt to close the server again.
    """
    loop = setup_test_loop()
    app = _create_example_app()
    client = _TestClient(_TestServer(app, loop=loop), loop=loop)
    loop.run_until_complete(client.close())
    loop.run_until_complete(client.close())
    teardown_test_loop(loop)
Exemplo n.º 14
0
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
Exemplo n.º 15
0
def test_server_with_create_test_teardown():
    with loop_context() as loop:
        app = _create_example_app()
        with _TestClient(_TestServer(app, loop=loop), loop=loop) as client:

            async def test_get_route():
                resp = await client.request("GET", "/")
                assert resp.status == 200
                text = await resp.text()
                assert _hello_world_str == text

            loop.run_until_complete(test_get_route())
Exemplo n.º 16
0
async def test_test_client_props(loop) -> None:
    app = _create_example_app()
    server = _TestServer(app, scheme='http', host='127.0.0.1', loop=loop)
    client = _TestClient(server, loop=loop)
    assert client.scheme == 'http'
    assert client.host == '127.0.0.1'
    assert client.port is None
    async with client:
        assert isinstance(client.port, int)
        assert client.server is not None
        assert client.app is not None
    assert client.port is None
Exemplo n.º 17
0
async def test_test_client_props() -> None:
    app = _create_example_app()
    server = _TestServer(app, scheme="http", host="127.0.0.1")
    client = _TestClient(server)
    assert client.scheme == "http"
    assert client.host == "127.0.0.1"
    assert client.port is None
    async with client:
        assert isinstance(client.port, int)
        assert client.server is not None
        assert client.app is not None
    assert client.port is None
def function282():
    with loop_context() as var2066:
        var2326 = function2617()
        with _TestClient(var2326, loop=var2066) as var292:

            @asyncio.coroutine
            def function2441():
                var1051 = yield from var292.request('GET', '/')
                assert (var1051.status == 200)
                var29 = yield from var1051.var29()
                assert ('Hello, world' in var29)
            var2066.run_until_complete(function2441())
Exemplo n.º 19
0
async def test_custom_port(loop: Any, app: Any, aiohttp_unused_port: Any) -> None:
    port = aiohttp_unused_port()
    client = _TestClient(_TestServer(app, port=port))
    await client.start_server()

    assert client.server.port == port

    resp = await client.get("/")
    assert resp.status == 200
    text = await resp.text()
    assert _hello_world_str == text

    await client.close()
def function509():
    with loop_context() as var71:
        var1867 = function2617()
        with _TestClient(var1867, loop=var71) as var2177:

            @asyncio.coroutine
            def function2441():
                nonlocal client
                var1595 = yield from var2177.request('GET', '/')
                assert (var1595.status == 200)
                var2663 = yield from var1595.var2663()
                assert ('Hello, world' in var2663)
            var71.run_until_complete(function2441())
Exemplo n.º 21
0
async def test_custom_port(loop, app, aiohttp_unused_port):
    port = aiohttp_unused_port()
    client = _TestClient(_TestServer(app, loop=loop, port=port), loop=loop)
    await client.start_server()

    assert client.server.port == port

    resp = await client.get('/')
    assert resp.status == 200
    text = await resp.text()
    assert _hello_world_str == text

    await client.close()
Exemplo n.º 22
0
def test_server_with_create_test_teardown():
    with loop_context() as loop:
        app = _create_example_app(loop)
        with _TestClient(app) as client:

            @asyncio.coroutine
            def test_get_route():
                resp = yield from client.request("GET", "/")
                assert resp.status == 200
                text = yield from resp.text()
                assert "Hello, world" in text

            loop.run_until_complete(test_get_route())
Exemplo n.º 23
0
async def test_test_client_raw_server_props(loop) -> None:
    async def hello(request):
        return web.Response(body=_hello_world_bytes)

    client = _TestClient(_RawTestServer(hello, host='127.0.0.1', loop=loop),
                         loop=loop)
    assert client.host == '127.0.0.1'
    assert client.port is None
    async with client:
        assert isinstance(client.port, int)
        assert client.server is not None
        assert client.app is None
    assert client.port is None
Exemplo n.º 24
0
def test_server_with_create_test_teardown():
    with loop_context() as loop:
        app = _create_example_app(loop)
        with _TestClient(app) as client:

            @asyncio.coroutine
            def test_get_route():
                resp = yield from client.request("GET", "/")
                assert resp.status == 200
                text = yield from resp.text()
                assert "Hello, world" in text

            loop.run_until_complete(test_get_route())
Exemplo n.º 25
0
def test_auto_gzip_decompress():
    with loop_context() as loop:
        app = _create_example_app()
        with _TestClient(_TestServer(app, loop=loop), loop=loop) as client:

            async def test_get_route():
                nonlocal client
                resp = await client.request("GET", "/gzip_hello")
                assert resp.status == 200
                data = await resp.read()
                assert data == _hello_world_bytes

            loop.run_until_complete(test_get_route())
Exemplo n.º 26
0
def test_full_server_scenario():
    with loop_context() as loop:
        app = _create_example_app()
        with _TestClient(app, loop=loop) as client:

            @asyncio.coroutine
            def test_get_route():
                nonlocal client
                resp = yield from client.request("GET", "/")
                assert resp.status == 200
                text = yield from resp.text()
                assert "Hello, world" in text

            loop.run_until_complete(test_get_route())
Exemplo n.º 27
0
def test_auto_gzip_decompress():
    with loop_context() as loop:
        app = _create_example_app()
        with _TestClient(_TestServer(app, loop=loop), loop=loop) as client:

            @asyncio.coroutine
            def test_get_route():
                nonlocal client
                resp = yield from client.request("GET", "/gzip_hello")
                assert resp.status == 200
                data = yield from resp.read()
                assert data == _hello_world_bytes

            loop.run_until_complete(test_get_route())
def test_full_server_scenario():
    with loop_context() as loop:
        app = _create_example_app()
        with _TestClient(_TestServer(app, loop=loop), loop=loop) as client:

            @asyncio.coroutine
            def test_get_route():
                nonlocal client
                resp = yield from client.request("GET", "/")
                assert resp.status == 200
                text = yield from resp.text()
                assert _hello_world_str == text

            loop.run_until_complete(test_get_route())
Exemplo n.º 29
0
async def test_test_client_raw_server_props(loop):

    async def hello(request):
        return web.Response(body=_hello_world_bytes)

    client = _TestClient(_RawTestServer(hello, host='127.0.0.1', loop=loop),
                         loop=loop)
    assert client.host == '127.0.0.1'
    assert client.port is None
    async with client:
        assert isinstance(client.port, int)
        assert client.server is not None
        assert client.app is None
    assert client.port is None
Exemplo n.º 30
0
async def test_test_client_raw_server_props() -> None:
    async def hello(request):
        return web.Response(body=_hello_world_bytes)

    server = _RawTestServer(hello, scheme="http", host="127.0.0.1")
    client = _TestClient(server)
    assert client.scheme == "http"
    assert client.host == "127.0.0.1"
    assert client.port is None
    async with client:
        assert isinstance(client.port, int)
        assert client.server is not None
        assert client.app is None
    assert client.port is None
def test_noauto_gzip_decompress():
    with loop_context() as loop:
        app = _create_example_app()
        with _TestClient(_TestServer(app, loop=loop),
                         loop=loop,
                         auto_decompress=False) as client:

            @asyncio.coroutine
            def test_get_route():
                nonlocal client
                resp = yield from client.request("GET", "/gzip_hello")
                assert resp.status == 200
                data = yield from resp.read()
                assert data == _hello_world_gz

            loop.run_until_complete(test_get_route())
Exemplo n.º 32
0
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
Exemplo n.º 33
0
def test_client_scheme_mutually_exclusive_with_server(loop):
    app = _create_example_app(loop)
    server = _TestServer(app)
    with pytest.raises(ValueError):
        _TestClient(server, scheme='http')
Exemplo n.º 34
0
def test_client(loop, app):
    client = _TestClient(app, loop=loop)
    loop.run_until_complete(client.start_server())
    yield client
    loop.run_until_complete(client.close())
Exemplo n.º 35
0
def test_client(loop, app):
    client = _TestClient(_TestServer(app, loop=loop), loop=loop)
    loop.run_until_complete(client.start_server())
    yield client
    loop.run_until_complete(client.close())
Exemplo n.º 36
0
def test_with_client_fails(loop):
    app = _create_example_app()
    with pytest.raises(TypeError):
        with _TestClient(_TestServer(app, loop=loop), loop=loop):
            pass
Exemplo n.º 37
0
def test_client_unsupported_arg():
    with pytest.raises(TypeError):
        _TestClient('string')
Exemplo n.º 38
0
def test_client_host_mutually_exclusive_with_server(loop):
    app = _create_example_app(loop)
    server = _TestServer(app)
    with pytest.raises(ValueError):
        _TestClient(server, host='127.0.0.1')
Exemplo n.º 39
0
def test_client_unsupported_arg():
    with pytest.raises(TypeError) as e:
        _TestClient('string')

    assert str(e.value) == \
        "server must be TestServer instance, found type: <class 'str'>"
Exemplo n.º 40
0
async def test_client_context_manager(app, loop):
    async with _TestClient(app) as client:
        resp = await client.head('/')
        assert resp.status == 200
Exemplo n.º 41
0
 async def make_client():
     return _TestClient(_TestServer(app, loop=loop), loop=loop)
Exemplo n.º 42
0
def test_client(loop, app):
    client = _TestClient(app)
    yield client
    client.close()
Exemplo n.º 43
0
def test_client_unsupported_arg():
    with pytest.raises(TypeError):
        _TestClient('string')