示例#1
0
 def test_sleeps_for_requested_time(self, sockets, mocksocket):
     ws = mocksocket
     ws.receive.return_value = 'somechannel:incoming message!'
     sockets.request = Mock()
     sockets.request.args.get.return_value = '.5'
     sockets.gevent = Mock()
     sockets.chat(ws)
     sockets.gevent.sleep.assert_called_once_with(0.5)
示例#2
0
 def test_chat_publishes_message_to_requested_channel(
         self, sockets, mocksocket):
     ws = mocksocket
     ws.receive.return_value = "special:incoming message!"
     sockets.request = Mock()
     sockets.request.args = {"tolerance": ".5"}
     sockets.chat(ws)
     sockets.redis_conn.publish.assert_called_once_with(
         "special", "incoming message!")
示例#3
0
 def test_chat_publishes_message_to_requested_channel(
         self, sockets, mocksocket):
     ws = mocksocket
     ws.receive.return_value = 'special:incoming message!'
     sockets.request = Mock()
     sockets.request.args = {'tolerance': '.5'}
     sockets.chat(ws)
     sockets.conn.publish.assert_called_once_with('special',
                                                  'incoming message!')
示例#4
0
    def test_chat_subscribes_to_requested_channel(self, sockets):
        ws = Mock()
        ws.closed = True
        sockets.request = Mock()
        sockets.request.args = {"channel": "special"}
        sockets.chat(ws)

        clients = [
            c for c in sockets.chat_backend.channels["special"].clients
            if c.ws is ws
        ]
        assert len(clients) == 1
示例#5
0
 def test_chat_subscribes_to_requested_channel(self, sockets):
     ws = Mock()
     sockets.request = Mock()
     sockets.request.args = {'channel': 'special'}
     sockets.chat(ws)
     assert ws in sockets.chat_backend.clients['special']