Add confirmation to Cast/Sonos/iOS config entries (#16769)

* Add confirmation to Cast/Sonos/iOS config entries

* Remove redundant code
This commit is contained in:
Paulus Schoutsen 2018-09-21 16:34:37 +02:00 committed by Pascal Vizeli
parent 213171769d
commit 8b42d0c471
5 changed files with 59 additions and 33 deletions

View file

@ -42,22 +42,24 @@ async def test_user_no_devices_found(hass, flow_conf):
"""Test if no devices found."""
flow = config_entries.HANDLERS['test']()
flow.hass = hass
result = await flow.async_step_user()
flow.context = {
'source': config_entries.SOURCE_USER
}
result = await flow.async_step_confirm(user_input={})
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
assert result['reason'] == 'no_devices_found'
async def test_user_no_confirmation(hass, flow_conf):
"""Test user requires no confirmation to set up."""
async def test_user_has_confirmation(hass, flow_conf):
"""Test user requires no confirmation to setup."""
flow = config_entries.HANDLERS['test']()
flow.hass = hass
flow_conf['discovered'] = True
result = await flow.async_step_user()
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
async def test_discovery_single_instance(hass, flow_conf):
@ -100,7 +102,7 @@ async def test_multiple_discoveries(hass, flow_conf):
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
async def test_user_init_trumps_discovery(hass, flow_conf):
async def test_only_one_in_progress(hass, flow_conf):
"""Test a user initialized one will finish and cancel discovered one."""
loader.set_component(hass, 'test', MockModule('test'))
@ -112,9 +114,16 @@ async def test_user_init_trumps_discovery(hass, flow_conf):
# User starts flow
result = await hass.config_entries.flow.async_init(
'test', context={'source': config_entries.SOURCE_USER}, data={})
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
# Discovery flow has been aborted
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
# Discovery flow has not been aborted
assert len(hass.config_entries.flow.async_progress()) == 2
# Discovery should be aborted once user confirms
result = await hass.config_entries.flow.async_configure(
result['flow_id'], {})
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert len(hass.config_entries.flow.async_progress()) == 0