Пример #1
0
    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)
Пример #2
0
 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)
Пример #3
0
    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()
Пример #4
0
    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()
Пример #5
0
    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()
Пример #6
0
    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'
Пример #7
0
    def test_human_readable(self):
        f = websockets.Frame()
        assert repr(f)

        f = websockets.Frame(b"foobar")
        assert "foobar" in repr(f)
Пример #8
0
 def round(*args, **kwargs):
     f = websockets.Frame(*args, **kwargs)
     raw = bytes(f)
     f2 = websockets.Frame.from_file(tutils.treader(raw))
     assert f == f2
Пример #9
0
    def test_equality(self):
        f = websockets.Frame(payload=b'1234')
        f2 = websockets.Frame(payload=b'1234')
        assert f == f2

        assert f != b'1234'
Пример #10
0
 def handle_websockets(cls, rfile, wfile):
     wfile.write(
         bytes(websockets.Frame(fin=1, opcode=15, payload=b'foobar')))
     wfile.flush()
Пример #11
0
 def test_human_readable(self):
     f = websockets.Frame()
     assert repr(f)
Пример #12
0
 def round(*args, **kwargs):
     f = websockets.Frame(*args, **kwargs)
     bytes = f.to_bytes()
     f2 = websockets.Frame.from_file(tutils.treader(bytes))
     assert f == f2
Пример #13
0
 def round(*args, **kwargs):
     f = websockets.Frame(*args, **kwargs)
     bytes = f.to_bytes()
     f2 = websockets.Frame.from_file(cStringIO.StringIO(bytes))
     assert f == f2