async def do(): request = HttpRequest("GET", "http://localhost:{}/basic/string".format(port)) policies = [UserAgentPolicy("myusergant"), AsyncRedirectPolicy()] async with AsyncPipeline(TrioRequestsTransport(), policies=policies) as pipeline: return await pipeline.run(request)
async def test_send_data(port): async with TrioRequestsTransport() as transport: request = HttpRequest('PUT', 'http://localhost:{}/basic/anything'.format(port), content=b"azerty") client = AsyncTestRestClient(port, transport=transport) response = await client.send_request(request) assert response.json()['data'] == "azerty"
async def do(): conf = Configuration() request = HttpRequest("GET", "https://bing.com/") policies = [UserAgentPolicy("myusergant"), AsyncRedirectPolicy()] async with AsyncPipeline(TrioRequestsTransport(conf), policies=policies) as pipeline: return await pipeline.run(request)
async def req(): request = HttpRequest("GET", "https://bing.com/") policies = [UserAgentPolicy("myuseragent"), AsyncRedirectPolicy()] # [START trio] from azure.core.pipeline.transport import TrioRequestsTransport async with AsyncPipeline(TrioRequestsTransport(), policies=policies) as pipeline: return await pipeline.run(request)
async def test_send_data(port, http_request): async with TrioRequestsTransport() as transport: req = http_request('PUT', 'http://localhost:{}/basic/anything'.format(port), data=b"azerty") response = await transport.send(req) if is_rest(http_request): assert is_rest(response) assert json.loads(response.text())['data'] == "azerty"
async def test_response_stream_download_trio(get_old_response_trio, get_new_response_trio): old_response = await get_old_response_trio(stream=True) new_response = await get_new_response_trio(stream=True) pipeline = Pipeline(TrioRequestsTransport()) old_string = b"".join([ part async for part in old_response.stream_download(pipeline=pipeline) ]) new_string = b"".join([ part async for part in new_response.stream_download(pipeline=pipeline) ]) assert old_string == new_string == b"Hello, world!"
async def test_async_gen_data(): class AsyncGen: def __init__(self): self._range = iter([b"azerty"]) def __aiter__(self): return self async def __anext__(self): try: return next(self._range) except StopIteration: raise StopAsyncIteration async with TrioRequestsTransport() as transport: req = HttpRequest('GET', 'http://httpbin.org/anything', data=AsyncGen()) response = await transport.send(req) assert json.loads(response.text())['data'] == "azerty"
async def test_async_gen_data(port): class AsyncGen: def __init__(self): self._range = iter([b"azerty"]) def __aiter__(self): return self async def __anext__(self): try: return next(self._range) except StopIteration: raise StopAsyncIteration async with TrioRequestsTransport() as transport: client = AsyncTestRestClient(port, transport=transport) request = HttpRequest('GET', 'http://localhost:{}/basic/anything'.format(port), content=AsyncGen()) response = await client.send_request(request) assert response.json()['data'] == "azerty"
async def test_async_gen_data(port, http_request): class AsyncGen: def __init__(self): self._range = iter([b"azerty"]) def __aiter__(self): return self async def __anext__(self): try: return next(self._range) except StopIteration: raise StopAsyncIteration async with TrioRequestsTransport() as transport: req = http_request('GET', 'http://localhost:{}/basic/anything'.format(port), data=AsyncGen()) response = await transport.send(req) if is_rest(http_request): assert is_rest(response) assert json.loads(response.text())['data'] == "azerty"
async def do(): async with TrioRequestsTransport() as transport: await transport.sleep(1)
async def do(): request = http_request("GET", "http://localhost:{}/basic/string".format(port)) async with TrioRequestsTransport() as sender: return await sender.send(request) assert response.body() is not None
async def do(): request = HttpRequest("GET", "https://www.bing.com/") async with TrioRequestsTransport() as sender: return await sender.send(request) assert response.body() is not None
async def _callback(**kwargs): async with TrioRequestsTransport() as sender: return await sender.send(new_request, **kwargs)
async def test_send_data(): async with TrioRequestsTransport() as transport: req = HttpRequest('PUT', 'http://httpbin.org/anything', data=b"azerty") response = await transport.send(req) assert json.loads(response.text())['data'] == "azerty"
async def client(port): async with TrioRequestsTransport() as transport: async with AsyncTestRestClient(port, transport=transport) as client: yield client