This commit is contained in:
Paulus Schoutsen 2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View file

@ -10,20 +10,21 @@ from tests.common import MockDependency, mock_coro
async def test_creating_entry_sets_up_media_player(hass):
"""Test setting up Cast loads the media player."""
with patch('homeassistant.components.cast.media_player.async_setup_entry',
return_value=mock_coro(True)) as mock_setup, \
MockDependency('pychromecast', 'discovery'), \
patch('pychromecast.discovery.discover_chromecasts',
return_value=True):
with patch(
"homeassistant.components.cast.media_player.async_setup_entry",
return_value=mock_coro(True),
) as mock_setup, MockDependency("pychromecast", "discovery"), patch(
"pychromecast.discovery.discover_chromecasts", return_value=True
):
result = await hass.config_entries.flow.async_init(
cast.DOMAIN, context={'source': config_entries.SOURCE_USER})
cast.DOMAIN, context={"source": config_entries.SOURCE_USER}
)
# Confirmation form
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
result = await hass.config_entries.flow.async_configure(
result['flow_id'], {})
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
await hass.async_block_till_done()
@ -32,16 +33,14 @@ async def test_creating_entry_sets_up_media_player(hass):
async def test_configuring_cast_creates_entry(hass):
"""Test that specifying config will create an entry."""
with patch('homeassistant.components.cast.async_setup_entry',
return_value=mock_coro(True)) as mock_setup, \
MockDependency('pychromecast', 'discovery'), \
patch('pychromecast.discovery.discover_chromecasts',
return_value=True):
await async_setup_component(hass, cast.DOMAIN, {
'cast': {
'some_config': 'to_trigger_import'
}
})
with patch(
"homeassistant.components.cast.async_setup_entry", return_value=mock_coro(True)
) as mock_setup, MockDependency("pychromecast", "discovery"), patch(
"pychromecast.discovery.discover_chromecasts", return_value=True
):
await async_setup_component(
hass, cast.DOMAIN, {"cast": {"some_config": "to_trigger_import"}}
)
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
@ -49,11 +48,11 @@ async def test_configuring_cast_creates_entry(hass):
async def test_not_configuring_cast_not_creates_entry(hass):
"""Test that no config will not create an entry."""
with patch('homeassistant.components.cast.async_setup_entry',
return_value=mock_coro(True)) as mock_setup, \
MockDependency('pychromecast', 'discovery'), \
patch('pychromecast.discovery.discover_chromecasts',
return_value=True):
with patch(
"homeassistant.components.cast.async_setup_entry", return_value=mock_coro(True)
) as mock_setup, MockDependency("pychromecast", "discovery"), patch(
"pychromecast.discovery.discover_chromecasts", return_value=True
):
await async_setup_component(hass, cast.DOMAIN, {})
await hass.async_block_till_done()