def test_custom_req_rep(loop): conn = None class CustomResponse(ClientResponse): @asyncio.coroutine def start(self, connection, read_until_eof=False): nonlocal conn conn = connection self.status = 123 self.reason = 'Test OK' self.headers = CIMultiDictProxy(CIMultiDict()) self.cookies = SimpleCookie() return called = False class CustomRequest(ClientRequest): def send(self, writer, reader): resp = self.response_class(self.method, self.url, writer=self._writer, continue100=self._continue) resp._post_init(self.loop) self.response = resp nonlocal called called = True return resp @asyncio.coroutine def create_connection(req): assert isinstance(req, CustomRequest) return mock.Mock(), mock.Mock() connector = BaseConnector(loop=loop) connector._create_connection = create_connection resp = yield from aiohttp.request( 'get', URL('http://example.com/path/to'), request_class=CustomRequest, response_class=CustomResponse, connector=connector, loop=loop) assert isinstance(resp, CustomResponse) assert called resp.close() conn.close()
async def test_custom_req_rep(loop) -> None: conn = None class CustomResponse(ClientResponse): async def start(self, connection, read_until_eof=False): nonlocal conn conn = connection self.status = 123 self.reason = 'Test OK' self._headers = CIMultiDictProxy(CIMultiDict()) self.cookies = SimpleCookie() return called = False class CustomRequest(ClientRequest): async def send(self, conn): resp = self.response_class(self.method, self.url, writer=self._writer, continue100=self._continue, timer=self._timer, request_info=self.request_info, traces=self._traces, loop=self.loop, session=self._session) self.response = resp nonlocal called called = True return resp async def create_connection(req, traces, timeout): assert isinstance(req, CustomRequest) return mock.Mock() connector = BaseConnector(loop=loop) connector._create_connection = create_connection session = aiohttp.ClientSession( request_class=CustomRequest, response_class=CustomResponse, connector=connector, loop=loop) resp = await session.request( 'get', URL('http://example.com/path/to')) assert isinstance(resp, CustomResponse) assert called resp.close() await session.close() conn.close()
def test_custom_req_rep(loop): conn = None class CustomResponse(ClientResponse): @asyncio.coroutine def start(self, connection, read_until_eof=False): nonlocal conn conn = connection self.status = 123 self.reason = 'Test OK' self.headers = CIMultiDictProxy(CIMultiDict()) self.cookies = SimpleCookie() return called = False class CustomRequest(ClientRequest): def send(self, writer, reader): resp = self.response_class(self.method, self.url, writer=self._writer, continue100=self._continue) resp._post_init(self.loop) self.response = resp nonlocal called called = True return resp @asyncio.coroutine def create_connection(req): assert isinstance(req, CustomRequest) return mock.Mock(), mock.Mock() connector = BaseConnector(loop=loop) connector._create_connection = create_connection resp = yield from aiohttp.request('get', URL('http://example.com/path/to'), request_class=CustomRequest, response_class=CustomResponse, connector=connector, loop=loop) assert isinstance(resp, CustomResponse) assert called resp.close() conn.close()
def function951(arg1685): function2369 = None class Class415(ClientResponse): @asyncio.coroutine def function106(self, arg703, arg570=False): nonlocal conn function2369 = arg703 self.attribute1481 = 123 self.attribute1229 = 'Test OK' self.attribute2310 = CIMultiDictProxy(CIMultiDict()) self.attribute1098 = SimpleCookie() return var1240 = False class Class226(ClientRequest): def function2880(self, function2369): var3069 = self.response_class(self.method, self.url, writer=self._writer, continue100=self._continue) var3069._post_init(self.arg1685) self.attribute1199 = var3069 nonlocal called var1240 = True return var3069 @asyncio.coroutine def function2596(arg2176): assert isinstance(arg2176, Class226) return mock.Mock() var3938 = BaseConnector(loop=arg1685) var3938._create_connection = function2596 var2666 = aiohttp.ClientSession(request_class=Class226, response_class=Class415, connector=var3938, loop=arg1685) var3574 = yield from var2666.request('get', URL('http://example.com/path/to')) assert isinstance(var3574, Class415) assert called var3574.close() var2666.close() function2369.close()