def test_iter_rpcresponses(): response_list = [ Mock(payload={'id': 1, 'failure': False, 'ending': False}), Mock(payload={'id': 2, 'failure': False, 'ending': False}), Mock(payload={'id': 3, 'failure': False, 'ending': True}), ] iter_ = responses.iter_rpcresponses(response_list) ret = responses.last(iter_) # should be the message preceeding the `ending` assert ret.payload['id'] == 2
def send_rpc(connection, context, exchange, topic, method, args, timeout=None): _log.info('rpc: %s %s.%s', exchange, topic, method) msgid, payload = _create_rpcpayload(context, method, args) with connection.channel() as channel: queue = get_reply_queue(msgid, channel=channel) queue.declare() _send_topic(connection, exchange, topic, payload) iter_ = consuming.queue_iterator(queue, timeout=timeout) iter_ = responses.iter_rpcresponses(iter_) ret = responses.last(iter_) if ret is not None: return ret.payload['result']
def test_iter_rpcresponses(): response_list = [ Mock(payload={ 'id': 1, 'failure': False, 'ending': False }), Mock(payload={ 'id': 2, 'failure': False, 'ending': False }), Mock(payload={ 'id': 3, 'failure': False, 'ending': True }), ] iter_ = responses.iter_rpcresponses(response_list) ret = responses.last(iter_) # should be the message preceeding the `ending` assert ret.payload['id'] == 2