Add context to login flow (#15914)
* Add context to login flow * source -> context * Fix unit test * Update comment
This commit is contained in:
1 parent
6d432d19fe
commit
34e1f1b6da
15 files changed
+36
-38
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""Tests for the Cast config flow."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import cast
|
||||
|
||||
@@ -15,7 +15,8 @@ async def test_creating_entry_sets_up_media_player(hass):
|
||||
MockDependency('pychromecast', 'discovery'), \
|
||||
patch('pychromecast.discovery.discover_chromecasts',
|
||||
return_value=True):
|
||||
result = await hass.config_entries.flow.async_init(cast.DOMAIN)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
cast.DOMAIN, context={'source': config_entries.SOURCE_USER})
|
||||
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -202,7 +202,6 @@ def test_create_account(hass, client):
|
||||
'handler': 'test',
|
||||
'title': 'Test Entry',
|
||||
'type': 'create_entry',
|
||||
'source': 'user',
|
||||
'version': 1,
|
||||
}
|
||||
|
||||
@@ -264,7 +263,6 @@ def test_two_step_flow(hass, client):
|
||||
'type': 'create_entry',
|
||||
'title': 'user-title',
|
||||
'version': 1,
|
||||
'source': 'user',
|
||||
}
|
||||
|
||||
|
||||
@@ -295,7 +293,7 @@ def test_get_progress_index(hass, client):
|
||||
{
|
||||
'flow_id': form['flow_id'],
|
||||
'handler': 'test',
|
||||
'source': 'hassio'
|
||||
'context': {'source': 'hassio'}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tests for the Sonos config flow."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import sonos
|
||||
|
||||
@@ -13,7 +13,8 @@ async def test_creating_entry_sets_up_media_player(hass):
|
||||
with patch('homeassistant.components.media_player.sonos.async_setup_entry',
|
||||
return_value=mock_coro(True)) as mock_setup, \
|
||||
patch('soco.discover', return_value=True):
|
||||
result = await hass.config_entries.flow.async_init(sonos.DOMAIN)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
sonos.DOMAIN, context={'source': config_entries.SOURCE_USER})
|
||||
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -109,7 +109,8 @@ async def test_user_init_trumps_discovery(hass, flow_conf):
|
||||
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
|
||||
|
||||
# User starts flow
|
||||
result = await hass.config_entries.flow.async_init('test', data={})
|
||||
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
|
||||
|
||||
@@ -116,7 +116,8 @@ def test_add_entry_calls_setup_entry(hass, manager):
|
||||
})
|
||||
|
||||
with patch.dict(config_entries.HANDLERS, {'comp': TestFlow, 'beer': 5}):
|
||||
yield from manager.flow.async_init('comp')
|
||||
yield from manager.flow.async_init(
|
||||
'comp', context={'source': config_entries.SOURCE_USER})
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
@@ -171,7 +172,8 @@ async def test_saving_and_loading(hass):
|
||||
)
|
||||
|
||||
with patch.dict(config_entries.HANDLERS, {'test': TestFlow}):
|
||||
await hass.config_entries.flow.async_init('test')
|
||||
await hass.config_entries.flow.async_init(
|
||||
'test', context={'source': config_entries.SOURCE_USER})
|
||||
|
||||
class Test2Flow(data_entry_flow.FlowHandler):
|
||||
VERSION = 3
|
||||
@@ -187,7 +189,8 @@ async def test_saving_and_loading(hass):
|
||||
|
||||
with patch('homeassistant.config_entries.HANDLERS.get',
|
||||
return_value=Test2Flow):
|
||||
await hass.config_entries.flow.async_init('test')
|
||||
await hass.config_entries.flow.async_init(
|
||||
'test', context={'source': config_entries.SOURCE_USER})
|
||||
|
||||
# To trigger the call_later
|
||||
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=1))
|
||||
|
||||
@@ -25,8 +25,10 @@ def manager():
|
||||
if context is not None else 'user_input'
|
||||
return flow
|
||||
|
||||
async def async_add_entry(result):
|
||||
async def async_add_entry(context, result):
|
||||
if (result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY):
|
||||
result['source'] = context.get('source') \
|
||||
if context is not None else 'user'
|
||||
entries.append(result)
|
||||
|
||||
manager = data_entry_flow.FlowManager(
|
||||
@@ -168,7 +170,7 @@ async def test_create_saves_data(manager):
|
||||
assert entry['handler'] == 'test'
|
||||
assert entry['title'] == 'Test Title'
|
||||
assert entry['data'] == 'Test Data'
|
||||
assert entry['source'] == 'user_input'
|
||||
assert entry['source'] == 'user'
|
||||
|
||||
|
||||
async def test_discovery_init_flow(manager):
|
||||
|
||||
Reference in new issue
Block a user