def _test_wamp_client(event_loop): transport = Mock(spec_set=('abort', 'close', 'write', 'get_extra_info')) transport.write = Mock(side_effect=lambda m: messages.append(m)) client = Mock(spec=['onOpen', 'onMessage']) def fact_client(): return client messages = [] proto = WampRawSocketClientFactory(fact_client)() proto.connection_made(transport) assert proto._serializer s = proto._serializer.RAWSOCKET_SERIALIZER_ID proto.data_received(bytes(bytearray([0x7F, 0xF0 | s, 0, 0]))) client.onOpen.assert_called_once_with(proto) proto.sendMessage(message.Abort('close')) for d in messages[1:]: proto.data_received(d) assert client.onMessage.called assert isinstance(client.onMessage.call_args[0][0], message.Abort)
def test_wamp(self): transport = Mock(spec_set=('abort', 'close', 'write', 'get_extra_info')) transport.write = Mock(side_effect=lambda m: messages.append(m)) client = Mock(spec=['onOpen', 'onMessage']) def fact(): return client messages = [] proto = WampRawSocketClientFactory(fact)() proto.connection_made(transport) self.assertTrue(proto._serializer) s = proto._serializer.RAWSOCKET_SERIALIZER_ID proto.data_received(bytes(bytearray([0x7F, 0xF0 | s, 0, 0]))) client.onOpen.assert_called_once_with(proto) proto.send(message.Abort(u'close')) for d in messages[1:]: proto.data_received(d) self.assertTrue(client.onMessage.called) self.assertTrue( isinstance(client.onMessage.call_args[0][0], message.Abort)) # server transport = Mock(spec_set=('abort', 'close', 'write', 'get_extra_info')) transport.write = Mock(side_effect=lambda m: messages.append(m)) client = None server = Mock(spec=['onOpen', 'onMessage']) def fact_server(): return server messages = [] proto = WampRawSocketServerFactory(fact_server)() proto.connection_made(transport) self.assertTrue(proto.factory._serializers) s = proto.factory._serializers[1].RAWSOCKET_SERIALIZER_ID proto.data_received(bytes(bytearray([0x7F, 0xF0 | s, 0, 0]))) self.assertTrue(proto._serializer) server.onOpen.assert_called_once_with(proto) proto.send(message.Abort(u'close')) for d in messages[1:]: proto.data_received(d) self.assertTrue(server.onMessage.called) self.assertTrue( isinstance(server.onMessage.call_args[0][0], message.Abort))
def test_wamp(self): transport = Mock(spec_set=('abort', 'close', 'write', 'get_extra_info')) transport.write = Mock(side_effect=lambda m: messages.append(m)) client = Mock(spec=['onOpen', 'onMessage']) def fact(): return client messages = [] proto = WampRawSocketClientFactory(fact)() proto.connection_made(transport) self.assertTrue(proto._serializer) s = proto._serializer.RAWSOCKET_SERIALIZER_ID proto.data_received(bytes(bytearray([0x7F, 0xF0 | s, 0, 0]))) client.onOpen.assert_called_once_with(proto) proto.send(message.Abort(u'close')) for d in messages[1:]: proto.data_received(d) self.assertTrue(client.onMessage.called) self.assertTrue(isinstance(client.onMessage.call_args[0][0], message.Abort)) # server transport = Mock(spec_set=('abort', 'close', 'write', 'get_extra_info')) transport.write = Mock(side_effect=lambda m: messages.append(m)) client = None server = Mock(spec=['onOpen', 'onMessage']) def fact_server(): return server messages = [] proto = WampRawSocketServerFactory(fact_server)() proto.connection_made(transport) self.assertTrue(proto.factory._serializers) s = proto.factory._serializers[1].RAWSOCKET_SERIALIZER_ID proto.data_received(bytes(bytearray([0x7F, 0xF0 | s, 0, 0]))) self.assertTrue(proto._serializer) server.onOpen.assert_called_once_with(proto) proto.send(message.Abort(u'close')) for d in messages[1:]: proto.data_received(d) self.assertTrue(server.onMessage.called) self.assertTrue(isinstance(server.onMessage.call_args[0][0], message.Abort))