'Test basic_publish().'

@patch(u'__builtin__.buffer')
@patch((QPID_MODULE + u'.Channel.body_encoding'))
@patch((QPID_MODULE + u'.Channel.encode_body'))
@patch((QPID_MODULE + u'.Channel._put'))
def test_basic_publish(self, mock_put, mock_encode_body, mock_body_encoding, mock_buffer):

    mock_original_body = Mock()
    mock_encoded_body = u'this    is    my    encoded    body'
    mock_message = {u'body': mock_original_body, u'properties': {u'delivery_info': {}}}
    mock_encode_body.return_value = (mock_encoded_body, mock_body_encoding)
    mock_exchange = Mock()
    mock_routing_key = Mock()
    mock_encoded_buffered_body = Mock()
    mock_buffer.return_value = mock_encoded_buffered_body
    self.my_channel.basic_publish(mock_message, mock_exchange, mock_routing_key)
    mock_encode_body.assert_called_once_with(mock_original_body, mock_body_encoding)
    mock_buffer.assert_called_once_with(mock_encoded_body)
    assert (mock_message[u'body'] is mock_encoded_buffered_body)
    assert (mock_message[u'properties'][u'body_encoding'] is mock_body_encoding)
    assert isinstance(mock_message[u'properties'][u'delivery_tag'], uuid.UUID)
    assert (mock_message[u'properties'][u'delivery_info'][u'exchange'] is mock_exchange)
    assert (mock_message[u'properties'][u'delivery_info'][u'routing_key'] is mock_routing_key)
    mock_put.assert_called_with(mock_routing_key, mock_message, mock_exchange)
