def test_open_connection_error(self): with test_utils.run_test_server(self.loop) as httpd: f = streams.open_connection(*httpd.address, loop=self.loop) reader, writer = self.loop.run_until_complete(f) writer._protocol.connection_lost(ZeroDivisionError()) f = reader.read() with self.assertRaises(ZeroDivisionError): self.loop.run_until_complete(f)
def test_open_connection(self): with test_utils.run_test_server(self.loop) as httpd: f = streams.open_connection(*httpd.address, loop=self.loop) reader, writer = self.loop.run_until_complete(f) writer.write(b'GET / HTTP/1.0\r\n\r\n') f = reader.readline() data = self.loop.run_until_complete(f) self.assertEqual(data, b'HTTP/1.0 200 OK\r\n') f = reader.read() data = self.loop.run_until_complete(f) self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
def test_open_connection_no_loop_ssl(self): with test_utils.run_test_server(self.loop, use_ssl=True) as httpd: try: events.set_event_loop(self.loop) f = streams.open_connection(*httpd.address, ssl=True) reader, writer = self.loop.run_until_complete(f) finally: events.set_event_loop(None) writer.write(b'GET / HTTP/1.0\r\n\r\n') f = reader.read() data = self.loop.run_until_complete(f) self.assertTrue(data.endswith(b'\r\n\r\nTest message'))