def test_closing_message_received(self):
     s = MagicMock()
     m = MagicMock()
     c = MagicMock()
     
     ws = WebSocket(sock=m)
     with patch.multiple(ws, close=c):
         ws.stream = s
         ws.stream.closing = CloseControlMessage(code=1000, reason='test closing')
         ws.process(b'unused for this test')
         c.assert_called_once_with(1000, b'test closing')
 def test_send_bytes_with_masking(self):
     tm = TextMessage(b'hello world').single(mask=True)
     
     m = MagicMock()
     ws = WebSocket(sock=m)
     ws.stream = MagicMock()
     ws.stream.always_mask = True
     ws.stream.text_message.return_value.single.return_value = tm
     
     ws.send(b'hello world')
     m.sendall.assert_called_once_with(tm)
Exemplo n.º 3
0
    def test_send_bytes_with_masking(self):
        tm = TextMessage(b'hello world').single(mask=True)

        m = MagicMock()
        ws = WebSocket(sock=m)
        ws.stream = MagicMock()
        ws.stream.always_mask = True
        ws.stream.text_message.return_value.single.return_value = tm

        ws.send(b'hello world')
        m.sendall.assert_called_once_with(tm)
Exemplo n.º 4
0
    def test_closing_message_received(self):
        s = MagicMock()
        m = MagicMock()
        c = MagicMock()

        ws = WebSocket(sock=m)
        with patch.multiple(ws, close=c):
            ws.stream = s
            ws.stream.closing = CloseControlMessage(code=1000,
                                                    reason='test closing')
            ws.process(b'unused for this test')
            c.assert_called_once_with(1000, b'test closing')
 def test_terminate_without_closing(self):
     m = MagicMock()
     s = MagicMock()
     c = MagicMock()
     cc = MagicMock()
     
     ws = WebSocket(sock=m)
     with patch.multiple(ws, closed=c, close_connection=cc):
         ws.stream = s
         ws.stream.closing = None
         ws.terminate()
         self.assertTrue(ws.client_terminated)
         self.assertTrue(ws.server_terminated)
         self.assertTrue(ws.terminated)
         c.assert_called_once_with(1006, "Going away")
         cc.assert_called_once_with()
         self.assertIsNone(ws.stream)
         self.assertIsNone(ws.environ)
 def test_terminate_with_closing(self):
     m = MagicMock()
     s = MagicMock()
     c = MagicMock()
     cc = MagicMock()
     
     ws = WebSocket(sock=m)
     with patch.multiple(ws, closed=c, close_connection=cc):
         ws.stream = s
         ws.stream.closing = CloseControlMessage(code=1000, reason='test closing')
         ws.terminate()
         self.assertTrue(ws.client_terminated)
         self.assertTrue(ws.server_terminated)
         self.assertTrue(ws.terminated)
         c.assert_called_once_with(1000, b'test closing')
         cc.assert_called_once_with()
         self.assertIsNone(ws.stream)
         self.assertIsNone(ws.environ)
Exemplo n.º 7
0
    def test_terminate_without_closing(self):
        m = MagicMock()
        s = MagicMock()
        c = MagicMock()
        cc = MagicMock()

        ws = WebSocket(sock=m)
        with patch.multiple(ws, closed=c, close_connection=cc):
            ws.stream = s
            ws.stream.closing = None
            ws.terminate()
            self.assertTrue(ws.client_terminated)
            self.assertTrue(ws.server_terminated)
            self.assertTrue(ws.terminated)
            c.assert_called_once_with(1006, "Going away")
            cc.assert_called_once_with()
            self.assertIsNone(ws.stream)
            self.assertIsNone(ws.environ)
Exemplo n.º 8
0
    def test_terminate_with_closing(self):
        m = MagicMock()
        s = MagicMock()
        c = MagicMock()
        cc = MagicMock()

        ws = WebSocket(sock=m)
        with patch.multiple(ws, closed=c, close_connection=cc):
            ws.stream = s
            ws.stream.closing = CloseControlMessage(code=1000,
                                                    reason='test closing')
            ws.terminate()
            self.assertTrue(ws.client_terminated)
            self.assertTrue(ws.server_terminated)
            self.assertTrue(ws.terminated)
            c.assert_called_once_with(1000, b'test closing')
            cc.assert_called_once_with()
            self.assertIsNone(ws.stream)
            self.assertIsNone(ws.environ)