def test_stop(self): s = self._socket() c = Connection(s) c.stop() # no packets should ever be returned after stoping # and it should return instantly eq_(list(c.packets()), [])
def test_send_packet_escaping(self): stream = six.BytesIO() c = Connection(stream) c.send_packet(1, """"Hello World""" "") eq_(stream.getvalue(), six.b('\x01\x01\x00\x00\x00\x00\x00\x0f"\\"Hello World"'))
def test_send_packet_escaping(self): stream = six.BytesIO() c = Connection(stream) c.send_packet(1, """"Hello World""""") eq_(stream.getvalue(), six.b('\x01\x01\x00\x00\x00\x00\x00\x0f"\\"Hello World"'))
def test_send_packet(self): stream = six.BytesIO() c = Connection(stream) c.send_packet(1, "Hello World") eq_(stream.getvalue(), six.b('\x01\x01\x00\x00\x00\x00\x00\r"Hello World"'))
def test_packets(self): s, stream = self._with_data(self._dummy_msg) c = Connection(s) kind, body = six.next(c.packets()) eq_(kind, 116) eq_(body, "Hello World") eq_(stream.tell(), len(self._dummy_msg))
def test_wrong_version(self): # Just a header, just reading the invalid # number causes an exception. # Version = 99, type = 1 len= 5 msg = six.b('c\x01\x00\x00\x00\x00\x00\x05') s, stream = self._with_data(msg) c = Connection(s) c.read_packet()
def test_read_packet(self): s = self._socket() # Version = 1, type = 't', len = 31 msg = self._dummy_msg s, stream = self._with_data(msg) c = Connection(s) kind, body = c.read_packet() eq_(kind, 116) eq_(body, "Hello World") eq_(stream.tell(), len(msg))
def test_start_with_socket(self): import gevent.socket as s mck = Mock(spec=s.socket) c = Connection(mck) mck.makefile.assert_called_once()
def _start(self): serv, cli, clifd = get_sockets() secret = "__NO_AUTH__" if self._secured: # pragma: nocover raise RuntimeError("Secure connections are not supported yet") self._proc = open_process(clifd, secret) self._con = Connection(serv) self._proto = Protocol(self._con, None if not self._secured else secret) self._proto.start()
def test_no_packets(self): s = self._socket() s.closed = True c = Connection(s) six.next(c.packets())