def test_close(self): client = self._setup_connection() client.wfile.write( bytes(websockets.Frame(fin=1, opcode=websockets.OPCODE.CLOSE))) client.wfile.flush() with pytest.raises(netlib.exceptions.TcpDisconnect): websockets.Frame.from_file(client.rfile)
def test_serialization_bijection(self, masked, length): frame = websockets.Frame( os.urandom(length), fin=True, opcode=websockets.OPCODE.TEXT, mask=int(masked), masking_key=(os.urandom(4) if masked else None)) serialized = bytes(frame) assert frame == websockets.Frame.from_bytes(serialized)
def handle_websockets(cls, rfile, wfile): wfile.write( bytes( websockets.Frame(fin=1, opcode=websockets.OPCODE.PING, payload=b'foobar'))) wfile.flush() frame = websockets.Frame.from_file(rfile) assert frame.header.opcode == websockets.OPCODE.PONG assert frame.payload == b'foobar' wfile.write( bytes( websockets.Frame(fin=1, opcode=websockets.OPCODE.TEXT, payload=b'pong-received'))) wfile.flush()
def test_simple_tls(self): client = self._setup_connection() frame = websockets.Frame.from_file(client.rfile) assert frame.payload == b'server-foobar' client.wfile.write( bytes( websockets.Frame(fin=1, opcode=websockets.OPCODE.TEXT, payload=b'client-foobar'))) client.wfile.flush() frame = websockets.Frame.from_file(client.rfile) assert frame.payload == b'client-foobar' client.wfile.write( bytes(websockets.Frame(fin=1, opcode=websockets.OPCODE.CLOSE))) client.wfile.flush()
def handle_websockets(cls, rfile, wfile): wfile.write( bytes( websockets.Frame(fin=1, opcode=websockets.OPCODE.TEXT, payload=b'server-foobar'))) wfile.flush() frame = websockets.Frame.from_file(rfile) wfile.write(bytes(frame)) wfile.flush()
def test_pong(self): client = self._setup_connection() client.wfile.write( bytes( websockets.Frame(fin=1, opcode=websockets.OPCODE.PING, payload=b'foobar'))) client.wfile.flush() frame = websockets.Frame.from_file(client.rfile) assert frame.header.opcode == websockets.OPCODE.PONG assert frame.payload == b'foobar'
def test_human_readable(self): f = websockets.Frame() assert repr(f) f = websockets.Frame(b"foobar") assert "foobar" in repr(f)
def round(*args, **kwargs): f = websockets.Frame(*args, **kwargs) raw = bytes(f) f2 = websockets.Frame.from_file(tutils.treader(raw)) assert f == f2
def test_equality(self): f = websockets.Frame(payload=b'1234') f2 = websockets.Frame(payload=b'1234') assert f == f2 assert f != b'1234'
def handle_websockets(cls, rfile, wfile): wfile.write( bytes(websockets.Frame(fin=1, opcode=15, payload=b'foobar'))) wfile.flush()
def test_human_readable(self): f = websockets.Frame() assert repr(f)
def round(*args, **kwargs): f = websockets.Frame(*args, **kwargs) bytes = f.to_bytes() f2 = websockets.Frame.from_file(tutils.treader(bytes)) assert f == f2
def round(*args, **kwargs): f = websockets.Frame(*args, **kwargs) bytes = f.to_bytes() f2 = websockets.Frame.from_file(cStringIO.StringIO(bytes)) assert f == f2