async def test_multiple_config_entry_created_when_installed( hass, app, locations, installed_apps, smartthings_mock): """Test a config entries are created for multiple installs.""" flow = SmartThingsFlowHandler() flow.hass = hass flow.access_token = str(uuid4()) flow.app_id = app.app_id flow.api = smartthings_mock.return_value flow.api.installed_apps.return_value = \ mock_coro(return_value=installed_apps) result = await flow.async_step_wait_install({}) assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result['data']['app_id'] == installed_apps[0].app_id assert result['data']['installed_app_id'] == \ installed_apps[0].installed_app_id assert result['data']['location_id'] == installed_apps[0].location_id assert result['data']['access_token'] == flow.access_token assert result['title'] == locations[0].name await hass.async_block_till_done() entries = hass.config_entries.async_entries('smartthings') assert len(entries) == 1 assert entries[0].data['app_id'] == installed_apps[1].app_id assert entries[0].data['installed_app_id'] == \ installed_apps[1].installed_app_id assert entries[0].data['location_id'] == installed_apps[1].location_id assert entries[0].data['access_token'] == flow.access_token assert entries[0].title == locations[1].name
async def test_config_entry_created_when_installed(hass, location, installed_app, smartthings_mock): """Test a config entry is created once the app is installed.""" flow = SmartThingsFlowHandler() flow.hass = hass flow.access_token = str(uuid4()) flow.app_id = installed_app.app_id flow.api = smartthings_mock flow.oauth_client_id = str(uuid4()) flow.oauth_client_secret = str(uuid4()) data = { CONF_REFRESH_TOKEN: str(uuid4()), CONF_LOCATION_ID: installed_app.location_id, CONF_INSTALLED_APP_ID: installed_app.installed_app_id, } hass.data[DOMAIN][CONF_INSTALLED_APPS].append(data) result = await flow.async_step_wait_install({}) assert not hass.data[DOMAIN][CONF_INSTALLED_APPS] assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["data"]["app_id"] == installed_app.app_id assert result["data"]["installed_app_id"] == installed_app.installed_app_id assert result["data"]["location_id"] == installed_app.location_id assert result["data"]["access_token"] == flow.access_token assert result["data"]["refresh_token"] == data[CONF_REFRESH_TOKEN] assert result["data"]["client_secret"] == flow.oauth_client_secret assert result["data"]["client_id"] == flow.oauth_client_id assert result["title"] == location.name
async def test_config_entry_created_when_installed( hass, location, installed_app, smartthings_mock): """Test a config entry is created once the app is installed.""" flow = SmartThingsFlowHandler() flow.hass = hass flow.access_token = str(uuid4()) flow.app_id = installed_app.app_id flow.api = smartthings_mock.return_value flow.oauth_client_id = str(uuid4()) flow.oauth_client_secret = str(uuid4()) data = { CONF_REFRESH_TOKEN: str(uuid4()), CONF_LOCATION_ID: installed_app.location_id, CONF_INSTALLED_APP_ID: installed_app.installed_app_id } hass.data[DOMAIN][CONF_INSTALLED_APPS].append(data) result = await flow.async_step_wait_install({}) assert not hass.data[DOMAIN][CONF_INSTALLED_APPS] assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result['data']['app_id'] == installed_app.app_id assert result['data']['installed_app_id'] == \ installed_app.installed_app_id assert result['data']['location_id'] == installed_app.location_id assert result['data']['access_token'] == flow.access_token assert result['data']['refresh_token'] == data[CONF_REFRESH_TOKEN] assert result['data']['client_secret'] == flow.oauth_client_secret assert result['data']['client_id'] == flow.oauth_client_id assert result['title'] == location.name
async def test_wait_form_displayed_after_checking(hass, smartthings_mock): """Test error is shown when the user has not installed the app.""" flow = SmartThingsFlowHandler() flow.hass = hass flow.access_token = str(uuid4()) flow.api = smartthings_mock.return_value flow.api.installed_apps.return_value = mock_coro(return_value=[]) result = await flow.async_step_wait_install({}) assert result['type'] == data_entry_flow.RESULT_TYPE_FORM assert result['step_id'] == 'wait_install' assert result['errors'] == {'base': 'app_not_installed'}
async def test_step_select_location_aborts(hass, location, smartthings_mock): """Test select location aborts if no available locations.""" smartthings_mock.locations.return_value = [location] entry = MockConfigEntry(domain=DOMAIN, data={CONF_LOCATION_ID: location.location_id}) entry.add_to_hass(hass) flow = SmartThingsFlowHandler() flow.hass = hass flow.api = smartthings_mock result = await flow.async_step_select_location() assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "no_available_locations"
async def test_step_select_location(hass, location, smartthings_mock): """Test select location shows form with available locations.""" smartthings_mock.locations.return_value = [location] flow = SmartThingsFlowHandler() flow.hass = hass flow.api = smartthings_mock result = await flow.async_step_select_location() assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "select_location" assert result["data_schema"]({ CONF_LOCATION_ID: location.location_id }) == { CONF_LOCATION_ID: location.location_id }
async def test_multiple_config_entry_created_when_installed( hass, app, locations, installed_apps, smartthings_mock): """Test a config entries are created for multiple installs.""" assert await async_setup_component(hass, "persistent_notification", {}) flow = SmartThingsFlowHandler() flow.hass = hass flow.access_token = str(uuid4()) flow.app_id = app.app_id flow.api = smartthings_mock flow.oauth_client_id = str(uuid4()) flow.oauth_client_secret = str(uuid4()) for installed_app in installed_apps: data = { CONF_REFRESH_TOKEN: str(uuid4()), CONF_LOCATION_ID: installed_app.location_id, CONF_INSTALLED_APP_ID: installed_app.installed_app_id, } hass.data[DOMAIN][CONF_INSTALLED_APPS].append(data) install_data = hass.data[DOMAIN][CONF_INSTALLED_APPS].copy() result = await flow.async_step_wait_install({}) assert not hass.data[DOMAIN][CONF_INSTALLED_APPS] assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["data"]["app_id"] == installed_apps[0].app_id assert result["data"]["installed_app_id"] == installed_apps[ 0].installed_app_id assert result["data"]["location_id"] == installed_apps[0].location_id assert result["data"]["access_token"] == flow.access_token assert result["data"]["refresh_token"] == install_data[0][ CONF_REFRESH_TOKEN] assert result["data"]["client_secret"] == flow.oauth_client_secret assert result["data"]["client_id"] == flow.oauth_client_id assert result["title"] == locations[0].name await hass.async_block_till_done() entries = hass.config_entries.async_entries("smartthings") assert len(entries) == 1 assert entries[0].data["app_id"] == installed_apps[1].app_id assert entries[0].data["installed_app_id"] == installed_apps[ 1].installed_app_id assert entries[0].data["location_id"] == installed_apps[1].location_id assert entries[0].data["access_token"] == flow.access_token assert entries[0].data["client_secret"] == flow.oauth_client_secret assert entries[0].data["client_id"] == flow.oauth_client_id assert entries[0].title == locations[1].name
async def test_multiple_config_entry_created_when_installed( hass, app, locations, installed_apps, smartthings_mock): """Test a config entries are created for multiple installs.""" flow = SmartThingsFlowHandler() flow.hass = hass flow.access_token = str(uuid4()) flow.app_id = app.app_id flow.api = smartthings_mock.return_value flow.oauth_client_id = str(uuid4()) flow.oauth_client_secret = str(uuid4()) for installed_app in installed_apps: data = { CONF_REFRESH_TOKEN: str(uuid4()), CONF_LOCATION_ID: installed_app.location_id, CONF_INSTALLED_APP_ID: installed_app.installed_app_id } hass.data[DOMAIN][CONF_INSTALLED_APPS].append(data) install_data = hass.data[DOMAIN][CONF_INSTALLED_APPS].copy() result = await flow.async_step_wait_install({}) assert not hass.data[DOMAIN][CONF_INSTALLED_APPS] assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result['data']['app_id'] == installed_apps[0].app_id assert result['data']['installed_app_id'] == \ installed_apps[0].installed_app_id assert result['data']['location_id'] == installed_apps[0].location_id assert result['data']['access_token'] == flow.access_token assert result['data']['refresh_token'] == \ install_data[0][CONF_REFRESH_TOKEN] assert result['data']['client_secret'] == flow.oauth_client_secret assert result['data']['client_id'] == flow.oauth_client_id assert result['title'] == locations[0].name await hass.async_block_till_done() entries = hass.config_entries.async_entries('smartthings') assert len(entries) == 1 assert entries[0].data['app_id'] == installed_apps[1].app_id assert entries[0].data['installed_app_id'] == \ installed_apps[1].installed_app_id assert entries[0].data['location_id'] == installed_apps[1].location_id assert entries[0].data['access_token'] == flow.access_token assert entries[0].data['client_secret'] == flow.oauth_client_secret assert entries[0].data['client_id'] == flow.oauth_client_id assert entries[0].title == locations[1].name
async def test_config_entry_created_when_installed( hass, location, installed_app, smartthings_mock): """Test a config entry is created once the app is installed.""" flow = SmartThingsFlowHandler() flow.hass = hass flow.access_token = str(uuid4()) flow.api = smartthings_mock.return_value flow.app_id = installed_app.app_id flow.api.installed_apps.return_value = \ mock_coro(return_value=[installed_app]) result = await flow.async_step_wait_install({}) assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result['data']['app_id'] == installed_app.app_id assert result['data']['installed_app_id'] == \ installed_app.installed_app_id assert result['data']['location_id'] == installed_app.location_id assert result['data']['access_token'] == flow.access_token assert result['title'] == location.name
async def test_config_entry_created_when_installed(hass, location, installed_app, smartthings_mock): """Test a config entry is created once the app is installed.""" flow = SmartThingsFlowHandler() flow.hass = hass flow.access_token = str(uuid4()) flow.api = smartthings_mock.return_value flow.app_id = installed_app.app_id flow.api.installed_apps.return_value = \ mock_coro(return_value=[installed_app]) result = await flow.async_step_wait_install({}) assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result['data']['app_id'] == installed_app.app_id assert result['data']['installed_app_id'] == \ installed_app.installed_app_id assert result['data']['location_id'] == installed_app.location_id assert result['data']['access_token'] == flow.access_token assert result['title'] == location.name
async def test_step_install_creates_entry(hass, location, smartthings_mock): """Test a config entry is created once the app is installed.""" flow = SmartThingsFlowHandler() flow.hass = hass flow.api = smartthings_mock flow.access_token = str(uuid4()) flow.app_id = str(uuid4()) flow.installed_app_id = str(uuid4()) flow.location_id = location.location_id flow.oauth_client_id = str(uuid4()) flow.oauth_client_secret = str(uuid4()) flow.refresh_token = str(uuid4()) result = await flow.async_step_install() assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["data"]["app_id"] == flow.app_id assert result["data"]["installed_app_id"] == flow.installed_app_id assert result["data"]["location_id"] == flow.location_id assert result["data"]["access_token"] == flow.access_token assert result["data"]["refresh_token"] == flow.refresh_token assert result["data"]["client_secret"] == flow.oauth_client_secret assert result["data"]["client_id"] == flow.oauth_client_id assert result["title"] == location.name