'Test the sending MQTT commands in optimistic mode.'

def test_sending_mqtt_commands_and_optimistic(self):

    assert setup_component(self.hass, switch.DOMAIN, {switch.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'command_topic': 'command-topic', 'payload_on': 'beer    on', 'payload_off': 'beer    off', 'qos': '2'}})
    state = self.hass.states.get('switch.test')
    self.assertEqual(STATE_OFF, state.state)
    self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
    switch.turn_on(self.hass, 'switch.test')
    self.hass.block_till_done()
    self.assertEqual(('command-topic', 'beer    on', 2, False), self.mock_publish.mock_calls[(-2)][1])
    state = self.hass.states.get('switch.test')
    self.assertEqual(STATE_ON, state.state)
    switch.turn_off(self.hass, 'switch.test')
    self.hass.block_till_done()
    self.assertEqual(('command-topic', 'beer    off', 2, False), self.mock_publish.mock_calls[(-2)][1])
    state = self.hass.states.get('switch.test')
    self.assertEqual(STATE_OFF, state.state)
