def test_del(self): response = HttpResponse('get', 'http://python.org') response._connection = unittest.mock.Mock() close = response.close = unittest.mock.Mock() del response self.assertTrue(close.called)
class HttpResponseTests(unittest.TestCase): def setUp(self): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) self.transport = unittest.mock.Mock() self.stream = aiohttp.StreamParser(loop=self.loop) self.response = HttpResponse('get', 'http://python.org') def tearDown(self): self.loop.close() def test_close(self): self.response.transport = self.transport self.response.close() self.assertIsNone(self.response.transport) self.assertTrue(self.transport.close.called) self.response.close() self.response.close() def test_repr(self): self.response.status = 200 self.response.reason = 'Ok' self.assertIn( '<HttpResponse(http://python.org) [200 Ok]>', repr(self.response))
def test_wait_for_100(self): response = HttpResponse( 'get', 'http://python.org', continue100=object()) self.assertTrue(response.wait_for_100()) response = HttpResponse( 'get', 'http://python.org') self.assertFalse(response.wait_for_100())
def setUp(self): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) self.transport = unittest.mock.Mock() self.stream = aiohttp.StreamParser(loop=self.loop) self.response = HttpResponse('get', 'http://python.org')
def test_del(self): response = HttpResponse('get', 'http://python.org') connection = unittest.mock.Mock() response._setup_connection(connection) del response connection.close.assert_called_with()
class HttpResponseTests(unittest.TestCase): def setUp(self): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) self.connection = unittest.mock.Mock() self.stream = aiohttp.StreamParser(loop=self.loop) self.response = HttpResponse('get', 'http://python.org') def tearDown(self): self.loop.close() def test_del(self): response = HttpResponse('get', 'http://python.org') response._connection = unittest.mock.Mock() close = response.close = unittest.mock.Mock() del response self.assertTrue(close.called) def test_close(self): self.response._connection = self.connection self.response.close() self.assertIsNone(self.response._connection) self.assertTrue(self.connection.release.called) self.response.close() self.response.close() def test_wait_for_100(self): response = HttpResponse( 'get', 'http://python.org', continue100=object()) self.assertTrue(response.waiting_for_continue()) response = HttpResponse( 'get', 'http://python.org') self.assertFalse(response.waiting_for_continue()) def test_repr(self): self.response.status = 200 self.response.reason = 'Ok' self.assertIn( '<HttpResponse(http://python.org) [200 Ok]>', repr(self.response)) def test_read_and_close(self): self.response.read = unittest.mock.Mock() self.response.read.return_value = asyncio.Future(loop=self.loop) self.response.read.return_value.set_result(b'payload') self.response.close = unittest.mock.Mock() res = self.loop.run_until_complete(self.response.read_and_close()) self.assertEqual(res, b'payload') self.assertTrue(self.response.read.called) self.assertTrue(self.response.close.called)
class HttpResponseTests(unittest.TestCase): def setUp(self): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) self.connection = unittest.mock.Mock() self.stream = aiohttp.StreamParser(loop=self.loop) self.response = HttpResponse('get', 'http://python.org') def tearDown(self): self.loop.close() def test_del(self): response = HttpResponse('get', 'http://python.org') response._connection = unittest.mock.Mock() close = response.close = unittest.mock.Mock() del response self.assertTrue(close.called) def test_close(self): self.response._connection = self.connection self.response.close() self.assertIsNone(self.response._connection) self.assertTrue(self.connection.release.called) self.response.close() self.response.close() def test_wait_for_100(self): response = HttpResponse('get', 'http://python.org', continue100=object()) self.assertTrue(response.waiting_for_continue()) response = HttpResponse('get', 'http://python.org') self.assertFalse(response.waiting_for_continue()) def test_repr(self): self.response.status = 200 self.response.reason = 'Ok' self.assertIn('<HttpResponse(http://python.org) [200 Ok]>', repr(self.response)) def test_read_and_close(self): self.response.read = unittest.mock.Mock() self.response.read.return_value = asyncio.Future(loop=self.loop) self.response.read.return_value.set_result(b'payload') self.response.close = unittest.mock.Mock() res = self.loop.run_until_complete(self.response.read_and_close()) self.assertEqual(res, b'payload') self.assertTrue(self.response.read.called) self.assertTrue(self.response.close.called)
def test_wait_for_100(self): response = HttpResponse('get', 'http://python.org', continue100=object()) self.assertTrue(response.waiting_for_continue()) response = HttpResponse('get', 'http://python.org') self.assertFalse(response.waiting_for_continue())
class HttpResponseTests(unittest.TestCase): def setUp(self): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) self.transport = unittest.mock.Mock() self.stream = aiohttp.StreamParser(loop=self.loop) self.response = HttpResponse('get', 'http://python.org') def tearDown(self): self.loop.close() def test_close(self): self.response.transport = self.transport self.response.close() self.assertIsNone(self.response.transport) self.assertTrue(self.transport.close.called) self.response.close() self.response.close() def test_repr(self): self.response.status = 200 self.response.reason = 'Ok' self.assertIn( '<HttpResponse(http://python.org) [200 Ok]>', repr(self.response)) def test_read_and_close(self): self.response.read = unittest.mock.Mock() self.response.read.return_value = asyncio.Future(loop=self.loop) self.response.read.return_value.set_result(b'payload') self.response.close = unittest.mock.Mock() res = self.loop.run_until_complete(self.response.read_and_close()) self.assertEqual(res, b'payload') self.assertTrue(self.response.read.called) self.assertTrue(self.response.close.called)
class HttpResponseTests(unittest.TestCase): def setUp(self): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) self.transport = unittest.mock.Mock() self.stream = aiohttp.StreamParser(loop=self.loop) self.response = HttpResponse('get', 'http://python.org') def tearDown(self): self.loop.close() def test_close(self): self.response.transport = self.transport self.response.close() self.assertIsNone(self.response.transport) self.assertTrue(self.transport.close.called) self.response.close() self.response.close() def test_repr(self): self.response.status = 200 self.response.reason = 'Ok' self.assertIn('<HttpResponse(http://python.org) [200 Ok]>', repr(self.response)) def test_read_and_close(self): self.response.read = unittest.mock.Mock() self.response.read.return_value = asyncio.Future(loop=self.loop) self.response.read.return_value.set_result(b'payload') self.response.close = unittest.mock.Mock() res = self.loop.run_until_complete(self.response.read_and_close()) self.assertEqual(res, b'payload') self.assertTrue(self.response.read.called) self.assertTrue(self.response.close.called)