async def test_empty_response(self, loop, console, results): async with self._get_session(loop, console, verbose=2) as session: request = Request() binary_body = b'' response = Response(body=binary_body) await session.send_event('response_received', response=response, request=request) await serialize(console)
async def test_encoding(self, loop, console, results): async with self._get_session(loop, console, verbose=2) as session: request = Request() binary_body = b'MZ\x90\x00\x03\x00\x00\x00\x04\x00' response = Response(body=binary_body) await session.send_event('response_received', response=response, request=request) res = await serialize(console) wanted = "can't display this body" self.assertTrue(wanted in res)
async def test_gzipped_response(self, loop, console, results): async with self._get_session(loop, console, verbose=2) as session: request = Request() binary_body = gzip.compress(b'some gzipped data') response = Response(body=binary_body) response.headers['Content-Encoding'] = 'gzip' await session.send_event('response_received', response=response, request=request) res = await serialize(console) self.assertTrue("Binary" in res, res)
async def test_gzipped_response(self, loop, console, results): async with self._get_session(loop, console, verbose=2) as session: request = Request() binary_body = gzip.compress(b"some gzipped data") response = Response(body=binary_body) response.headers["Content-Encoding"] = "gzip" await get_eventer(session).send_event("response_received", response=response, request=request) res = await serialize(console) self.assertTrue("Binary" in res, res)
async def test_not_verbose(self, loop, console, results): async with self._get_session(loop, console, verbose=1) as session: req = ClientRequest('GET', URL('http://example.com')) await session.send_event('sending_request', request=req) response = Response(body='') request = Request() await session.send_event('response_received', response=response, request=request) res = await serialize(console) self.assertEqual(res, '')
async def test_not_verbose(self, loop, console, results): async with self._get_session(loop, console, verbose=1) as session: req = ClientRequest("GET", URL("http://example.com")) await session.send_event("sending_request", request=req) response = Response(body="") request = Request() await session.send_event("response_received", response=response, request=request) res = await serialize(console) self.assertEqual(res, "")
async def test_add_listener(self, loop, console, results): class MyListener(BaseListener): def __init__(self): self.responses = [] def on_response_received(self, **options): self.responses.append(options['response']) lis = MyListener() async with self._get_session(loop, console, verbose=2) as session: session.eventer.add_listener(lis) request = Request() binary_body = b'' response = Response(body=binary_body) await session.send_event('response_received', response=response, request=request) await serialize(console) self.assertEqual(lis.responses, [response])