def test_failed_event(): # Create environment server, session, transport, conn = _get_test_environment(EventConnection) # Send event transport.recv(proto.event(None, 'test', None, a=10, b=20)) # Check response eq_(transport.pop_outgoing(), proto.event(None, 'test', None, a=10, b=20)) # Throw invalid event transport.recv(proto.event(None, 'test', None, a=10))
def test_failed_event(): # Create environment server, session, transport, conn = _get_test_environment(EventConnection) # Send event transport.recv(proto.event(None, 'test', a=10, b=20)) # Check response eq_(transport.pop_outgoing(), proto.event(None, 'test', a=10, b=20)) # Throw invalid event transport.recv(proto.event(None, 'test', a=10))
def test_event(): # Create environment server, session, transport, conn = _get_test_environment() # Send event transport.recv(proto.event(None, None, 'test', a=10, b=20)) # Send event with multiple parameters transport.recv('5:::{"name":"test", "args":[10, 20]}') # Check incoming eq_(conn.pop_event(), ('test', dict(a=10, b=20))) # Check outgoing eq_(transport.pop_outgoing(), proto.event(None, 'test', a=10, b=20))
def test_event(): # Create environment server, session, transport, conn = _get_test_environment() # Send event transport.recv(proto.event(None, 'test', None, a=10, b=20)) # Send event with multiple parameters transport.recv('5:::{"name":"test", "args":[10, 20]}') # Check incoming eq_(conn.pop_event(), ('test', dict(a=10, b=20))) # Check outgoing eq_(transport.pop_outgoing(), proto.event(None, 'test', None, a=10, b=20))
def emit(self, name, *args, **kwargs): """Send socket.io event. `name` Name of the event `kwargs` Optional event parameters """ msg = proto.event(self.endpoint, name, None, *args, **kwargs) self.session.send_message(msg)
def test_ack(): # Create environment server, session, transport, conn = _get_test_environment() # Send message with ACK transport.recv(proto.message(None, 'abc', 1)) # Check that message was received by the connection eq_(conn.pop_incoming(), 'abc') # Check for ACK eq_(transport.pop_outgoing(), '3:::abc') eq_(transport.pop_outgoing(), '6:::1') # Send with ACK def handler(msg, data): eq_(msg, 'abc') eq_(data, None) conn.send('yes') conn.send('abc', handler) eq_(transport.pop_outgoing(), '3:1::abc') # Send ACK from client transport.recv('6:::1') # Check if handler was called eq_(transport.pop_outgoing(), '3:::yes') # Test ack with event # Send event with multiple parameters transport.recv(proto.event(None, 'test', 1, a=10, b=20)) # Check outgoing eq_(transport.pop_outgoing(), proto.event(None, 'test', None, a=10, b=20)) eq_(transport.pop_outgoing(), proto.ack(None, 1, 'test'))
def emit_ack(self, callback, name, *args, **kwargs): """Send socket.io event with acknowledgment. `callback` Acknowledgment callback `name` Name of the event `kwargs` Optional event parameters """ msg = proto.event(self.endpoint, name, self.queue_ack(callback, (name, args, kwargs)), *args, **kwargs) self.session.send_message(msg)
def on_refresh_connection(self, endpoint_name): logging.debug('* * * Refresh connection') data_list = self.get_missed_ops(self.client_cts) if len(data_list): logging.debug('* * * %i new operations:' % len(data_list)) for op in data_list: logging.debug(repr(op)) # dirty hack server_cts = get_cts() self.client_cts = server_cts msg = proto.event(endpoint_name, 'operations', None, {'ops' : data_list, 'new_cts' : server_cts}) self.session.send_queue.append(msg) return True cur_date = datetime.now() dt = cur_date - self.connection_date if dt.seconds / 3600.0 > 2: return False return True
def on_refresh_connection(self, endpoint_name): logging.debug('* * * Refresh connection') data_list = self.get_missed_ops(self.client_cts) if len(data_list): logging.debug('* * * %i new operations:' % len(data_list)) for op in data_list: logging.debug(repr(op)) # dirty hack server_cts = get_cts() self.client_cts = server_cts msg = proto.event(endpoint_name, 'operations', None, { 'ops': data_list, 'new_cts': server_cts }) self.session.send_queue.append(msg) return True cur_date = datetime.now() dt = cur_date - self.connection_date if dt.seconds / 3600.0 > 2: return False return True
def test_event_get_tree(self, m_emit): session = EdtrRouter.create_session(self.request) session.raw_message(proto.event(None, 'get_tree', None)) self.sleep() m_emit.assert_called()