Exemplo n.º 1
0
 def test_websocket(self):
     ws = yield self.http.get(self.ws, websocket_handler=MessageHandler()
                              ).on_headers
     self.assertTrue(ws)
     self.assertIsInstance(ws.handler, MessageHandler)
     ws.write('Hello there!')
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'Hello there!')
Exemplo n.º 2
0
Arquivo: ws.py Projeto: tourist/lux
 def on_open(self, websocket):
     ws = WsClient(websocket, self)
     if self.pubsub:
         self.pubsub.add_client(ws)
         app = websocket.app
         app.fire('on_websocket_open', websocket, self)
     #
     # Send the LUX_CONNECTION event with socket id and start time
     ws.write(LUX_CONNECTION, socket_id=ws.session_id, time=ws.started)
Exemplo n.º 3
0
 def __test_websocket(self):
     #TODO: this fails. Something to do with queue
     ws = yield self.http.get(self.ws, websocket_handler=MessageHandler()
                              ).on_headers
     self.assertTrue(ws)
     self.assertIsInstance(ws.handler, MessageHandler)
     ws.write('Hello there!')
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'Hello there!')
Exemplo n.º 4
0
 def test_rpc(self):
     '''Send a message to the rpc'''
     ws = yield self.http.get(self.ws,
                              websocket_handler=MessageHandler()).on_headers
     self.assertEqual(ws.handshake.status_code, 101)
     ws.write('Hello there!')
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'Hello there!')
     result = yield self.rpc.message('Hi!')
     self.assertEqual(result, 'OK')
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'Hi!')
Exemplo n.º 5
0
 def test_rpc(self):
     '''Send a message to the rpc'''
     loop = self.http._loop
     ws = yield from self.http.get(self.ws, websocket_handler=Message(loop))
     self.assertEqual(ws.status_code, 101)
     ws.write('Hello there!')
     data = yield from ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'Hello there!')
     result = yield from self.rpc.message('Hi!')
     self.assertEqual(result, 'OK')
     data = yield from ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'Hi!')
Exemplo n.º 6
0
 def test_rpc(self):
     '''Send a message to the rpc'''
     ws = yield self.http.get(self.ws,
                              websocket_handler=MessageHandler()
                              ).on_headers
     self.assertEqual(ws.handshake.status_code, 101)
     ws.write('Hello there!')
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'Hello there!')
     result = yield self.rpc.message('Hi!')
     self.assertEqual(result, 'OK')
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'Hi!')
Exemplo n.º 7
0
 def test_websocket(self):
     ws = yield self.http.get(self.ws, websocket_handler=MessageHandler())
     response = ws.handshake
     self.assertEqual(response.status_code, 101)
     self.assertEqual(response.headers["upgrade"], "websocket")
     self.assertEqual(response.connection, ws.connection)
     self.assertTrue(ws.connection)
     self.assertIsInstance(ws.handler, MessageHandler)
     #
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data["message"], "joined")
     #
     ws.write("Hello there!")
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data["message"], "Hello there!")
Exemplo n.º 8
0
 def test_websocket(self):
     c = self.http
     ws = yield c.get(self.ws, websocket_handler=MessageHandler(c._loop))
     response = ws.handshake
     self.assertEqual(response.status_code, 101)
     self.assertEqual(response.headers['upgrade'], 'websocket')
     self.assertEqual(response.connection, ws.connection)
     self.assertTrue(ws.connection)
     self.assertIsInstance(ws.handler, MessageHandler)
     #
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'joined')
     #
     ws.write('Hello there!')
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'Hello there!')
Exemplo n.º 9
0
 def test_websocket(self):
     c = self.http
     ws = yield c.get(self.ws, websocket_handler=MessageHandler(c._loop))
     response = ws.handshake
     self.assertEqual(response.status_code, 101)
     self.assertEqual(response.headers['upgrade'], 'websocket')
     self.assertEqual(response.connection, ws.connection)
     self.assertTrue(ws.connection)
     self.assertIsInstance(ws.handler, MessageHandler)
     #
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'joined')
     #
     ws.write('Hello there!')
     data = yield ws.handler.get()
     data = json.loads(data)
     self.assertEqual(data['message'], 'Hello there!')
Exemplo n.º 10
0
 async def test_websocket(self):
     c = self.http
     ws = await c.get(self.ws, websocket_handler=MessageHandler(c._loop))
     response = ws.handshake
     self.assertEqual(response.status_code, 101)
     self.assertEqual(response.headers['upgrade'], 'websocket')
     self.assertEqual(response.connection, ws.connection)
     self.assertTrue(ws.connection)
     self.assertIsInstance(ws.handler, MessageHandler)
     # send a message
     ws.write('Hi there!')
     message = await ws.handler.queue.get()
     self.assertTrue(message)
     data = json.loads(message)
     self.assertEqual(data['message'], 'Hi there!')
     self.assertEqual(data['channel'], 'webchat')
     self.assertFalse(data['authenticated'])
     #
     # close connection
     ws.write_close()
     await ws.connection.event('connection_lost').waiter()