Esempio 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!')
Esempio n. 2
0
File: ws.py Progetto: 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)
Esempio 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!')
Esempio 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!')
Esempio 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!')
Esempio 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!')
Esempio 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!")
Esempio 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!')
Esempio 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!')
Esempio 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()