'Test the sending MQTT commands in optimistic mode.'

def test_sending_mqtt_commands_and_optimistic(self):

    assert setup_component(self.hass, lock.DOMAIN, {lock.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'command_topic': 'command-topic', 'payload_lock': 'LOCK', 'payload_unlock': 'UNLOCK', 'qos': 2}})
    state = self.hass.states.get('lock.test')
    self.assertEqual(STATE_UNLOCKED, state.state)
    self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
    lock.lock(self.hass, 'lock.test')
    self.hass.block_till_done()
    self.assertEqual(('command-topic', 'LOCK', 2, False), self.mock_publish.mock_calls[(-2)][1])
    state = self.hass.states.get('lock.test')
    self.assertEqual(STATE_LOCKED, state.state)
    lock.unlock(self.hass, 'lock.test')
    self.hass.block_till_done()
    self.assertEqual(('command-topic', 'UNLOCK', 2, False), self.mock_publish.mock_calls[(-2)][1])
    state = self.hass.states.get('lock.test')
    self.assertEqual(STATE_UNLOCKED, state.state)
