2017-12-08 09:40:45 +00:00
|
|
|
"""The tests for the Canary component."""
|
2020-09-13 16:32:41 +00:00
|
|
|
from requests import HTTPError
|
2017-12-08 09:40:45 +00:00
|
|
|
|
2020-09-13 16:32:41 +00:00
|
|
|
from homeassistant.components.canary import DOMAIN
|
|
|
|
from homeassistant.setup import async_setup_component
|
2019-12-09 17:56:21 +00:00
|
|
|
|
2020-09-13 16:32:41 +00:00
|
|
|
from tests.async_mock import patch
|
2017-12-08 09:40:45 +00:00
|
|
|
|
|
|
|
|
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"}}
|
2017-12-08 09:40:45 +00:00
|
|
|
|
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()
|
2017-12-08 09:40:45 +00:00
|
|
|
|
|
|
|
|
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"}}
|
2017-12-08 09:40:45 +00:00
|
|
|
|
2020-09-13 16:32:41 +00:00
|
|
|
canary.side_effect = HTTPError()
|
2017-12-08 09:40:45 +00:00
|
|
|
|
2020-09-13 16:32:41 +00:00
|
|
|
assert not await async_setup_component(hass, DOMAIN, config)
|
|
|
|
await hass.async_block_till_done()
|