'make sure on connection tune turns the connection params'

@mock.patch('pika.heartbeat.HeartbeatChecker')
@mock.patch('pika.frame.Method')
def test_on_connection_tune(self, method, heartbeat_checker):

    heartbeat_checker.return_value = 'hearbeat    obj'
    self.connection._flush_outbound = mock.Mock()
    marshal = mock.Mock(return_value='ab')
    method.return_value = mock.Mock(marshal=marshal)
    self.connection._rpc = mock.Mock()
    method_frame = mock.Mock()
    method_frame.method = mock.Mock()
    method_frame.method.channel_max = 40
    method_frame.method.frame_max = 10000
    method_frame.method.heartbeat = 10
    self.connection.params.channel_max = 20
    self.connection.params.frame_max = 20000
    self.connection.params.heartbeat = 20
    self.connection._on_connection_tune(method_frame)
    self.assertEqual(self.connection.CONNECTION_TUNE, self.connection.connection_state)
    self.assertEqual(20, self.connection.params.channel_max)
    self.assertEqual(10000, self.connection.params.frame_max)
    self.assertEqual(20, self.connection.params.heartbeat)
    self.assertEqual(9992, self.connection._body_max_length)
    heartbeat_checker.assert_called_once_with(self.connection, 20)
    self.assertEqual(['ab'], list(self.connection.outbound_buffer))
    self.assertEqual('hearbeat    obj', self.connection.heartbeat)
    method_frame.method.heartbeat = 60
    self.connection.params.heartbeat = 20
    self.connection._on_connection_tune(method_frame)
    self.assertEqual(60, self.connection.params.heartbeat)
    method_frame.method.heartbeat = 500
    self.connection.params.heartbeat = None
    self.connection._on_connection_tune(method_frame)
    self.assertEqual(500, self.connection.params.heartbeat)
    method_frame.method.heartbeat = 0
    self.connection.params.heartbeat = None
    self.connection._on_connection_tune(method_frame)
    self.assertEqual(0, self.connection.params.heartbeat)
    method_frame.method.heartbeat = 60
    self.connection.params.heartbeat = 0
    self.connection._on_connection_tune(method_frame)
    self.assertEqual(0, self.connection.params.heartbeat)
    method_frame.method.heartbeat = 0
    self.connection.params.heartbeat = 60
    self.connection._on_connection_tune(method_frame)
    self.assertEqual(0, self.connection.params.heartbeat)
    method_frame.method.heartbeat = 0
    self.connection.params.heartbeat = 0
    self.connection._on_connection_tune(method_frame)
    self.assertEqual(0, self.connection.params.heartbeat)
