core/tests/components/cast/test_init.py

48 lines
1.6 KiB
Python
Raw Normal View History

"""Tests for the Cast integration."""
from unittest.mock import patch
from homeassistant.components import cast
from homeassistant.setup import async_setup_component
async def test_import(hass, caplog):
"""Test that specifying config will create an entry."""
2019-07-31 19:25:30 +00:00
with patch(
2020-04-30 23:31:00 +00:00
"homeassistant.components.cast.async_setup_entry", return_value=True
2020-07-29 21:46:14 +00:00
) as mock_setup:
2019-07-31 19:25:30 +00:00
await async_setup_component(
hass,
cast.DOMAIN,
{
"cast": {
"media_player": [
{"uuid": "abcd"},
{"uuid": "abcd", "ignore_cec": "milk"},
{"uuid": "efgh", "ignore_cec": "beer"},
{"incorrect": "config"},
]
}
},
2019-07-31 19:25:30 +00:00
)
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
assert len(hass.config_entries.async_entries("cast")) == 1
entry = hass.config_entries.async_entries("cast")[0]
assert set(entry.data["ignore_cec"]) == {"milk", "beer"}
assert set(entry.data["uuid"]) == {"abcd", "efgh"}
assert "Invalid config '{'incorrect': 'config'}'" in caplog.text
async def test_not_configuring_cast_not_creates_entry(hass):
"""Test that an empty config does not create an entry."""
2019-07-31 19:25:30 +00:00
with patch(
2020-04-30 23:31:00 +00:00
"homeassistant.components.cast.async_setup_entry", return_value=True
2020-07-29 21:46:14 +00:00
) as mock_setup:
await async_setup_component(hass, cast.DOMAIN, {})
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 0