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
async def test_test_server_context_manager(loop): app = _create_example_app() async with _TestServer(app, loop=loop) as server: client = aiohttp.ClientSession(loop=loop) resp = await client.head(server.make_url('/')) assert resp.status == 200 resp.close() await client.close()
async def test_server_make_url_yarl_compatibility(loop): app = _create_example_app() async with _TestServer(app, loop=loop) as server: make_url = server.make_url assert make_url(URL('/foo')) == make_url('/foo') with pytest.raises(AssertionError): make_url('http://foo.com') with pytest.raises(AssertionError): make_url(URL('http://foo.com'))
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()
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
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)
def test_test_server_context_manager(loop): app = _create_example_app(loop) with _TestServer(app) as server: @asyncio.coroutine def go(): client = aiohttp.ClientSession(loop=loop) resp = yield from client.head(server.make_url('/')) assert resp.status == 200 resp.close() yield from client.close() loop.run_until_complete(go())
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: @asyncio.coroutine def test_get_route(): 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())
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()
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())
async def test_test_server_hostnames(hostname, expected_host, loop) -> None: app = _create_example_app() server = _TestServer(app, host=hostname, loop=loop) async with server: pass assert server.host == expected_host
def test_with_test_server_fails(loop) -> None: app = _create_example_app() with pytest.raises(TypeError): with _TestServer(app, loop=loop): pass
async def make_client(): return _TestClient(_TestServer(app, loop=loop), loop=loop)
async def test_server_context_manager(app, loop): async with _TestServer(app, loop=loop) as server: async with aiohttp.ClientSession(loop=loop) as client: async with client.head(server.make_url('/')) as resp: assert resp.status == 200
def function1427(): function4 = function2617() var327 = _TestServer(function4) with pytest.raises(ValueError): _TestClient(var327, host='127.0.0.1')
def test_with_client_fails(loop): app = _create_example_app() with pytest.raises(TypeError): with _TestClient(_TestServer(app, loop=loop), loop=loop): pass
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())
async def make_client(): return _TestClient(_TestServer(app))
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')
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')
async def test_server_context_manager(app: Any, loop: Any) -> None: async with _TestServer(app) as server: async with aiohttp.ClientSession() as client: async with client.head(server.make_url("/")) as resp: assert resp.status == 200
def function1879(): function4 = function2617() var1483 = _TestServer(function4) with pytest.raises(ValueError): _TestClient(var1483, scheme='http')