async def test_full_flow_implementation(hass): """Test registering an implementation and finishing flow works.""" config_flow.register_flow_implementation(hass, None, None) flow = await init_config_flow(hass) result = await flow.async_step_user() assert result['type'] == data_entry_flow.RESULT_TYPE_FORM assert result['step_id'] == 'auth' assert result['description_placeholders']['cb_url']\ == 'https://hass.com/api/ambiclimate' url = result['description_placeholders']['authorization_url'] assert 'https://api.ambiclimate.com/oauth2/authorize' in url assert 'client_id=id' in url assert 'response_type=code' in url assert 'redirect_uri=https%3A%2F%2Fhass.com%2Fapi%2Fambiclimate' in url with patch('ambiclimate.AmbiclimateOAuth.get_access_token', return_value=mock_coro('test')): result = await flow.async_step_code('123ABC') assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result['title'] == 'Ambiclimate' assert result['data']['callback_url'] == 'https://hass.com/api/ambiclimate' assert result['data']['client_secret'] == 'secret' assert result['data']['client_id'] == 'id' with patch('ambiclimate.AmbiclimateOAuth.get_access_token', return_value=mock_coro(None)): result = await flow.async_step_code('123ABC') assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT with patch('ambiclimate.AmbiclimateOAuth.get_access_token', side_effect=ambiclimate.AmbiclimateOauthError()): result = await flow.async_step_code('123ABC') assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
async def test_full_flow_implementation(hass): """Test registering an implementation and finishing flow works.""" config_flow.register_flow_implementation(hass, None, None) flow = await init_config_flow(hass) result = await flow.async_step_user() assert result["type"] == data_entry_flow.FlowResultType.FORM assert result["step_id"] == "auth" assert (result["description_placeholders"]["cb_url"] == "https://example.com/api/ambiclimate") url = result["description_placeholders"]["authorization_url"] assert "https://api.ambiclimate.com/oauth2/authorize" in url assert "client_id=id" in url assert "response_type=code" in url assert "redirect_uri=https%3A%2F%2Fexample.com%2Fapi%2Fambiclimate" in url with patch("ambiclimate.AmbiclimateOAuth.get_access_token", return_value="test"): result = await flow.async_step_code("123ABC") assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY assert result["title"] == "Ambiclimate" assert result["data"][ "callback_url"] == "https://example.com/api/ambiclimate" assert result["data"][CONF_CLIENT_SECRET] == "secret" assert result["data"][CONF_CLIENT_ID] == "id" with patch("ambiclimate.AmbiclimateOAuth.get_access_token", return_value=None): result = await flow.async_step_code("123ABC") assert result["type"] == data_entry_flow.FlowResultType.ABORT with patch( "ambiclimate.AmbiclimateOAuth.get_access_token", side_effect=ambiclimate.AmbiclimateOauthError(), ): result = await flow.async_step_code("123ABC") assert result["type"] == data_entry_flow.FlowResultType.ABORT