'test on data available and process frame'

@mock.patch('pika.frame.decode_frame')
def test_on_data_available(self, decode_frame):

    data_in = ['data']
    self.connection._frame_buffer = ['old_data']
    for frame_type in (frame.Method, spec.Basic.Deliver, frame.Heartbeat):
        frame_value = mock.Mock(spec=frame_type)
        frame_value.frame_type = 2
        frame_value.method = 2
        frame_value.channel_number = 1
        self.connection.bytes_received = 0
        self.connection.heartbeat = mock.Mock()
        self.connection.frames_received = 0
        decode_frame.return_value = (2, frame_value)
        self.connection._on_data_available(data_in)
        self.assertListEqual([], self.connection._frame_buffer)
        self.assertEqual(2, self.connection.bytes_received)
        self.assertEqual(1, self.connection.frames_received)
        if (frame_type == frame.Heartbeat):
            self.assertTrue(self.connection.heartbeat.received.called)
