예제 #1
0
def test_batch_dispatch(dispatch):
    method1 = Mock(return_value='rv1')
    method2 = Mock(return_value=None)

    dispatch.add_method(method1, 'method1')
    dispatch.add_method(method2, 'method2')

    batch_request = RPCBatchRequest()
    batch_request.error_respond = Mock(return_value='ERROR')
    batch_request.append(mock_request('method1', args=[1, 2]))
    batch_request.append(mock_request('non_existant_method', args=[5, 6]))
    batch_request.append(mock_request('method2', args=[3, 4]))

    batch_request.create_batch_response = lambda: RPCBatchResponse()

    assert batch_request.error_respond.call_count == 0

    response = dispatch.dispatch(batch_request)

    # assert all methods are called
    method1.assert_called_with(1, 2)
    method2.assert_called_with(3, 4)
예제 #2
0
def test_async_batch_dispatch(async_dispatch, event_loop):
    method1 = Mock(return_value=create_successful_future('rv1', event_loop))
    method2 = Mock(return_value=create_successful_future(None, event_loop))

    async_dispatch.add_method(method1, 'method1')
    async_dispatch.add_method(method2, 'method2')

    batch_request = RPCBatchRequest()
    batch_request.error_respond = Mock(return_value='ERROR')
    batch_request.append(mock_request('method1', args=[1, 2]))
    batch_request.append(mock_request('non_existant_method', args=[5, 6]))
    batch_request.append(mock_request('method2', args=[3, 4]))

    batch_request.create_batch_response = lambda: RPCBatchResponse()

    assert batch_request.error_respond.call_count == 0

    response = event_loop.run_until_complete(
        async_dispatch.dispatch(batch_request))

    # assert all methods are called
    method1.assert_called_with(1, 2)
    method2.assert_called_with(3, 4)