コード例 #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!')
コード例 #2
0
ファイル: ws.py プロジェクト: 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)
コード例 #3
0
ファイル: app.py プロジェクト: pombredanne/minilab
 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!')
コード例 #4
0
ファイル: tests.py プロジェクト: japaks/pulsar
 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!')
コード例 #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!')
コード例 #6
0
ファイル: tests.py プロジェクト: elimisteve/pulsar
 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!')
コード例 #7
0
ファイル: app.py プロジェクト: huobao36/pulsar
 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!")
コード例 #8
0
ファイル: app.py プロジェクト: azazel75/pulsar
 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!')
コード例 #9
0
ファイル: app.py プロジェクト: axisofentropy/pulsar
 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!')
コード例 #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()