Continue on invalid platforms and new setup_component unit tests (#3736)
This commit is contained in:
parent
1b26b5ad14
commit
7b40a641ec
23 changed files with 842 additions and 672 deletions
|
@ -1,14 +1,15 @@
|
|||
"""The tests the MQTT alarm control panel component."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.bootstrap import _setup_component
|
||||
from homeassistant.bootstrap import setup_component
|
||||
from homeassistant.const import (
|
||||
STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY,
|
||||
STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED, STATE_UNKNOWN)
|
||||
from homeassistant.components import alarm_control_panel
|
||||
|
||||
from tests.common import (
|
||||
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant)
|
||||
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant,
|
||||
assert_setup_component)
|
||||
|
||||
CODE = 'HELLO_CODE'
|
||||
|
||||
|
@ -16,7 +17,9 @@ CODE = 'HELLO_CODE'
|
|||
class TestAlarmControlPanelMQTT(unittest.TestCase):
|
||||
"""Test the manual alarm module."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
# pylint: disable=invalid-name
|
||||
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.mock_publish = mock_mqtt_component(self.hass)
|
||||
|
@ -28,27 +31,30 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
|||
def test_fail_setup_without_state_topic(self):
|
||||
"""Test for failing with no state topic."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert not _setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'command_topic': 'alarm/command'
|
||||
}
|
||||
})
|
||||
with assert_setup_component(0) as config:
|
||||
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'command_topic': 'alarm/command'
|
||||
}
|
||||
})
|
||||
assert not config[alarm_control_panel.DOMAIN]
|
||||
|
||||
def test_fail_setup_without_command_topic(self):
|
||||
"""Test failing with no command topic."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert not _setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'state_topic': 'alarm/state'
|
||||
}
|
||||
})
|
||||
with assert_setup_component(0):
|
||||
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'state_topic': 'alarm/state'
|
||||
}
|
||||
})
|
||||
|
||||
def test_update_state_via_state_topic(self):
|
||||
"""Test updating with via state topic."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
|
@ -72,7 +78,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
|||
def test_ignore_update_state_if_unknown_via_state_topic(self):
|
||||
"""Test ignoring updates via state topic."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
|
@ -93,7 +99,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
|||
def test_arm_home_publishes_mqtt(self):
|
||||
"""Test publishing of MQTT messages while armed."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
|
@ -110,7 +116,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
|||
def test_arm_home_not_publishes_mqtt_with_invalid_code(self):
|
||||
"""Test not publishing of MQTT messages with invalid code."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
|
@ -128,7 +134,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
|||
def test_arm_away_publishes_mqtt(self):
|
||||
"""Test publishing of MQTT messages while armed."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
|
@ -145,7 +151,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
|||
def test_arm_away_not_publishes_mqtt_with_invalid_code(self):
|
||||
"""Test not publishing of MQTT messages with invalid code."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
|
@ -163,7 +169,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
|||
def test_disarm_publishes_mqtt(self):
|
||||
"""Test publishing of MQTT messages while disarmed."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
|
@ -180,7 +186,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
|||
def test_disarm_not_publishes_mqtt_with_invalid_code(self):
|
||||
"""Test not publishing of MQTT messages with invalid code."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
|
||||
alarm_control_panel.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue