コード例 #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'>"
    )
コード例 #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
コード例 #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()
コード例 #4
0
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)
コード例 #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
コード例 #6
0
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)
コード例 #7
0
    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)
コード例 #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
コード例 #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()
コード例 #10
0
ファイル: test_test_utils.py プロジェクト: abogushov/aiohttp
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
コード例 #11
0
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
コード例 #12
0
ファイル: test_test_utils.py プロジェクト: avamsi/aiohttp
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()
コード例 #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)
コード例 #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
コード例 #15
0
ファイル: test_test_utils.py プロジェクト: kalaspuff/aiohttp
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())
コード例 #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
コード例 #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
コード例 #18
0
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())
コード例 #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()
コード例 #20
0
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())
コード例 #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()
コード例 #22
0
ファイル: test_test_utils.py プロジェクト: abogushov/aiohttp
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())
コード例 #23
0
ファイル: test_test_utils.py プロジェクト: zj1866/aiohttp
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
コード例 #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())
コード例 #25
0
ファイル: test_test_utils.py プロジェクト: kalaspuff/aiohttp
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())
コード例 #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())
コード例 #27
0
ファイル: test_test_utils.py プロジェクト: sunghyunzz/aiohttp
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())
コード例 #28
0
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())
コード例 #29
0
ファイル: test_test_utils.py プロジェクト: 3lnc/aiohttp
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
コード例 #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
コード例 #31
0
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())
コード例 #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
コード例 #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')
コード例 #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())
コード例 #35
0
ファイル: test_test_utils.py プロジェクト: 3lnc/aiohttp
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())
コード例 #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
コード例 #37
0
def test_client_unsupported_arg():
    with pytest.raises(TypeError):
        _TestClient('string')
コード例 #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')
コード例 #39
0
ファイル: test_test_utils.py プロジェクト: 3lnc/aiohttp
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'>"
コード例 #40
0
async def test_client_context_manager(app, loop):
    async with _TestClient(app) as client:
        resp = await client.head('/')
        assert resp.status == 200
コード例 #41
0
 async def make_client():
     return _TestClient(_TestServer(app, loop=loop), loop=loop)
コード例 #42
0
ファイル: test_test_utils.py プロジェクト: avamsi/aiohttp
def test_client(loop, app):
    client = _TestClient(app)
    yield client
    client.close()
コード例 #43
0
ファイル: test_test_utils.py プロジェクト: abogushov/aiohttp
def test_client_unsupported_arg():
    with pytest.raises(TypeError):
        _TestClient('string')