Exemple #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'')
Exemple #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'')
Exemple #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'')
Exemple #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'')
Exemple #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, '', ''))
Exemple #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, ''))
Exemple #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', ''))
Exemple #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', ''))
Exemple #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", ""))
Exemple #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"))
Exemple #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'')
Exemple #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'')
Exemple #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', ''))
Exemple #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', ''))