Ejemplo n.º 1
0
 def test_close_frame_invalid(self, m_parse_frame):
     def parse_frame(buf):
         yield
         return (1, websocket.OPCODE_CLOSE, b'1')
     m_parse_frame.side_effect = parse_frame
     buf = aiohttp.ParserBuffer()
     p = websocket.parse_message(buf)
     next(p)
     self.assertRaises(websocket.WebSocketError, p.send, b'')
Ejemplo n.º 2
0
 def test_unknown_frame(self, m_parse_frame):
     def parse_frame(buf):
         yield
         return (1, websocket.OPCODE_CONTINUATION, b'')
     m_parse_frame.side_effect = parse_frame
     buf = aiohttp.ParserBuffer()
     p = websocket.parse_message(buf)
     next(p)
     self.assertRaises(websocket.WebSocketError, p.send, b'')
Ejemplo n.º 3
0
 def test_unknown_frame(self, m_parse_frame):
     def parse_frame(buf):
         yield
         return (1, websocket.OPCODE_CONTINUATION, b'')
     m_parse_frame.side_effect = parse_frame
     buf = aiohttp.ParserBuffer()
     p = websocket.parse_message(buf)
     next(p)
     self.assertRaises(websocket.WebSocketError, p.send, b'')
Ejemplo n.º 4
0
 def test_close_frame_invalid(self, m_parse_frame):
     def parse_frame(buf):
         yield
         return (1, websocket.OPCODE_CLOSE, b'1')
     m_parse_frame.side_effect = parse_frame
     buf = aiohttp.ParserBuffer()
     p = websocket.parse_message(buf)
     next(p)
     self.assertRaises(websocket.WebSocketError, p.send, b'')
Ejemplo n.º 5
0
 def test_close_frame(self, m_parse_frame):
     def parse_frame(buf):
         yield
         return (1, websocket.OPCODE_CLOSE, b'')
     m_parse_frame.side_effect = parse_frame
     p = websocket.parse_message(aiohttp.ParserBuffer())
     next(p)
     try:
         p.send(b'')
     except StopIteration as exc:
         res = exc.value
     self.assertEqual(res, (websocket.OPCODE_CLOSE, '', ''))
Ejemplo n.º 6
0
 def test_close_frame(self, m_parse_frame):
     def parse_frame(buf):
         yield
         return (1, websocket.OPCODE_CLOSE, b'')
     m_parse_frame.side_effect = parse_frame
     p = websocket.parse_message(aiohttp.ParserBuffer())
     next(p)
     try:
         p.send(b'')
     except StopIteration as exc:
         res = exc.value
     self.assertEqual(res, (websocket.OPCODE_CLOSE, 0, ''))
Ejemplo n.º 7
0
 def test_simple_binary(self, m_parse_frame):
     def parse_frame(buf):
         yield
         return (1, websocket.OPCODE_BINARY, b'binary')
     m_parse_frame.side_effect = parse_frame
     buf = aiohttp.ParserBuffer()
     p = websocket.parse_message(buf)
     next(p)
     try:
         p.send(b'')
     except StopIteration as exc:
         res = exc.value
     self.assertEqual(res, (websocket.OPCODE_BINARY, b'binary', ''))
Ejemplo n.º 8
0
 def test_simple_binary(self, m_parse_frame):
     def parse_frame(buf):
         yield
         return (1, websocket.OPCODE_BINARY, b'binary')
     m_parse_frame.side_effect = parse_frame
     buf = aiohttp.ParserBuffer()
     p = websocket.parse_message(buf)
     next(p)
     try:
         p.send(b'')
     except StopIteration as exc:
         res = exc.value
     self.assertEqual(res, (websocket.OPCODE_BINARY, b'binary', ''))
Ejemplo n.º 9
0
    def test_simple_text(self, m_parse_frame):
        def parse_frame(buf):
            yield
            return (1, websocket.OPCODE_TEXT, b"text")

        m_parse_frame.side_effect = parse_frame
        buf = aiohttp.ParserBuffer()
        p = websocket.parse_message(buf)
        next(p)
        try:
            p.send(b"")
        except StopIteration as exc:
            res = exc.value
        self.assertEqual(res, (websocket.OPCODE_TEXT, "text", ""))
Ejemplo n.º 10
0
    def test_close_frame_info(self, m_parse_frame):
        def parse_frame(buf):
            yield
            return (1, websocket.OPCODE_CLOSE, b"0112345")

        m_parse_frame.side_effect = parse_frame
        buf = aiohttp.ParserBuffer()
        p = websocket.parse_message(buf)
        next(p)
        try:
            p.send(b"")
        except StopIteration as exc:
            res = exc.value
        self.assertEqual(res, (websocket.OPCODE_CLOSE, 12337, b"12345"))
Ejemplo n.º 11
0
    def test_continuation_err(self, m_parse_frame):
        cur = 0

        def parse_frame(buf):
            nonlocal cur
            yield
            if cur == 0:
                cur = 1
                return (0, websocket.OPCODE_TEXT, b'line1')
            else:
                return (1, websocket.OPCODE_TEXT, b'line2')

        m_parse_frame.side_effect = parse_frame
        buf = aiohttp.ParserBuffer()
        p = websocket.parse_message(buf)
        next(p)
        p.send(b'')
        self.assertRaises(websocket.WebSocketError, p.send, b'')
Ejemplo n.º 12
0
    def test_continuation_err(self, m_parse_frame):
        cur = 0

        def parse_frame(buf):
            nonlocal cur
            yield
            if cur == 0:
                cur = 1
                return (0, websocket.OPCODE_TEXT, b'line1')
            else:
                return (1, websocket.OPCODE_TEXT, b'line2')

        m_parse_frame.side_effect = parse_frame
        buf = aiohttp.ParserBuffer()
        p = websocket.parse_message(buf)
        next(p)
        p.send(b'')
        self.assertRaises(websocket.WebSocketError, p.send, b'')
Ejemplo n.º 13
0
    def test_continuation(self, m_parse_frame):
        cur = 0

        def parse_frame(buf):
            nonlocal cur
            yield
            if cur == 0:
                cur = 1
                return (0, websocket.OPCODE_TEXT, b'line1')
            else:
                return (1, websocket.OPCODE_CONTINUATION, b'line2')

        m_parse_frame.side_effect = parse_frame
        buf = aiohttp.ParserBuffer()
        p = websocket.parse_message(buf)
        next(p)
        p.send(b'')
        try:
            p.send(b'')
        except StopIteration as exc:
            res = exc.value
        self.assertEqual(res, (websocket.OPCODE_TEXT, 'line1line2', ''))
Ejemplo n.º 14
0
    def test_continuation(self, m_parse_frame):
        cur = 0

        def parse_frame(buf):
            nonlocal cur
            yield
            if cur == 0:
                cur = 1
                return (0, websocket.OPCODE_TEXT, b'line1')
            else:
                return (1, websocket.OPCODE_CONTINUATION, b'line2')

        m_parse_frame.side_effect = parse_frame
        buf = aiohttp.ParserBuffer()
        p = websocket.parse_message(buf)
        next(p)
        p.send(b'')
        try:
            p.send(b'')
        except StopIteration as exc:
            res = exc.value
        self.assertEqual(res, (websocket.OPCODE_TEXT, 'line1line2', ''))