core/tests/components/canary/test_init.py

38 lines
1.3 KiB
Python
Raw Normal View History

"""The tests for the Canary component."""
2020-09-13 16:32:41 +00:00
from requests import HTTPError
2020-09-13 16:32:41 +00:00
from homeassistant.components.canary import DOMAIN
from homeassistant.setup import async_setup_component
2020-09-13 16:32:41 +00:00
from tests.async_mock import patch
2020-09-13 16:32:41 +00:00
async def test_setup_with_valid_config(hass, canary) -> None:
"""Test setup with valid YAML."""
await async_setup_component(hass, "persistent_notification", {})
config = {DOMAIN: {"username": "test-username", "password": "test-password"}}
2020-09-13 16:32:41 +00:00
with patch(
"homeassistant.components.canary.alarm_control_panel.setup_platform",
return_value=True,
), patch(
"homeassistant.components.canary.camera.setup_platform",
return_value=True,
), patch(
"homeassistant.components.canary.sensor.setup_platform",
return_value=True,
):
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
2020-09-13 16:32:41 +00:00
async def test_setup_with_http_error(hass, canary) -> None:
"""Test setup with HTTP error."""
await async_setup_component(hass, "persistent_notification", {})
config = {DOMAIN: {"username": "test-username", "password": "test-password"}}
2020-09-13 16:32:41 +00:00
canary.side_effect = HTTPError()
2020-09-13 16:32:41 +00:00
assert not await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()