|  | 
| 25 | 25 |     CONF_VERIFY_SSL: True, | 
| 26 | 26 | } | 
| 27 | 27 | 
 | 
|  | 28 | +USER_INPUT_RECONFIGURE = { | 
|  | 29 | +    CONF_URL: "https://new_domain:9000/", | 
|  | 30 | +    CONF_API_TOKEN: "new_api_key", | 
|  | 31 | +    CONF_VERIFY_SSL: True, | 
|  | 32 | +} | 
|  | 33 | + | 
| 28 | 34 | 
 | 
| 29 | 35 | async def test_form( | 
| 30 | 36 |     hass: HomeAssistant, | 
| @@ -222,3 +228,86 @@ async def test_reauth_flow_exceptions( | 
| 222 | 228 |     assert result["reason"] == "reauth_successful" | 
| 223 | 229 |     assert mock_config_entry.data[CONF_API_TOKEN] == "new_api_key" | 
| 224 | 230 |     assert len(mock_setup_entry.mock_calls) == 1 | 
|  | 231 | + | 
|  | 232 | + | 
|  | 233 | +async def test_full_flow_reconfigure( | 
|  | 234 | +    hass: HomeAssistant, | 
|  | 235 | +    mock_portainer_client: AsyncMock, | 
|  | 236 | +    mock_setup_entry: MagicMock, | 
|  | 237 | +    mock_config_entry: MockConfigEntry, | 
|  | 238 | +) -> None: | 
|  | 239 | +    """Test the full flow of the config flow.""" | 
|  | 240 | +    mock_config_entry.add_to_hass(hass) | 
|  | 241 | +    result = await mock_config_entry.start_reconfigure_flow(hass) | 
|  | 242 | +    assert result["type"] is FlowResultType.FORM | 
|  | 243 | +    assert result["step_id"] == "reconfigure" | 
|  | 244 | + | 
|  | 245 | +    result = await hass.config_entries.flow.async_configure( | 
|  | 246 | +        result["flow_id"], | 
|  | 247 | +        user_input=USER_INPUT_RECONFIGURE, | 
|  | 248 | +    ) | 
|  | 249 | + | 
|  | 250 | +    assert result["type"] is FlowResultType.ABORT | 
|  | 251 | +    assert result["reason"] == "reconfigure_successful" | 
|  | 252 | +    assert mock_config_entry.data[CONF_API_TOKEN] == "new_api_key" | 
|  | 253 | +    assert mock_config_entry.data[CONF_URL] == "https://new_domain:9000/" | 
|  | 254 | +    assert mock_config_entry.data[CONF_VERIFY_SSL] is True | 
|  | 255 | +    assert len(mock_setup_entry.mock_calls) == 1 | 
|  | 256 | + | 
|  | 257 | + | 
|  | 258 | +@pytest.mark.parametrize( | 
|  | 259 | +    ("exception", "reason"), | 
|  | 260 | +    [ | 
|  | 261 | +        ( | 
|  | 262 | +            PortainerAuthenticationError, | 
|  | 263 | +            "invalid_auth", | 
|  | 264 | +        ), | 
|  | 265 | +        ( | 
|  | 266 | +            PortainerConnectionError, | 
|  | 267 | +            "cannot_connect", | 
|  | 268 | +        ), | 
|  | 269 | +        ( | 
|  | 270 | +            PortainerTimeoutError, | 
|  | 271 | +            "timeout_connect", | 
|  | 272 | +        ), | 
|  | 273 | +        ( | 
|  | 274 | +            Exception("Some other error"), | 
|  | 275 | +            "unknown", | 
|  | 276 | +        ), | 
|  | 277 | +    ], | 
|  | 278 | +) | 
|  | 279 | +async def test_full_flow_reconfigure_exceptions( | 
|  | 280 | +    hass: HomeAssistant, | 
|  | 281 | +    mock_portainer_client: AsyncMock, | 
|  | 282 | +    mock_setup_entry: MagicMock, | 
|  | 283 | +    mock_config_entry: MockConfigEntry, | 
|  | 284 | +    exception: Exception, | 
|  | 285 | +    reason: str, | 
|  | 286 | +) -> None: | 
|  | 287 | +    """Test the full flow of the config flow, this time with exceptions.""" | 
|  | 288 | +    mock_config_entry.add_to_hass(hass) | 
|  | 289 | +    result = await mock_config_entry.start_reconfigure_flow(hass) | 
|  | 290 | +    assert result["type"] is FlowResultType.FORM | 
|  | 291 | +    assert result["step_id"] == "reconfigure" | 
|  | 292 | + | 
|  | 293 | +    mock_portainer_client.get_endpoints.side_effect = exception | 
|  | 294 | +    result = await hass.config_entries.flow.async_configure( | 
|  | 295 | +        result["flow_id"], | 
|  | 296 | +        user_input=USER_INPUT_RECONFIGURE, | 
|  | 297 | +    ) | 
|  | 298 | + | 
|  | 299 | +    assert result["type"] is FlowResultType.FORM | 
|  | 300 | +    assert result["errors"] == {"base": reason} | 
|  | 301 | + | 
|  | 302 | +    mock_portainer_client.get_endpoints.side_effect = None | 
|  | 303 | +    result = await hass.config_entries.flow.async_configure( | 
|  | 304 | +        result["flow_id"], | 
|  | 305 | +        user_input=USER_INPUT_RECONFIGURE, | 
|  | 306 | +    ) | 
|  | 307 | + | 
|  | 308 | +    assert result["type"] is FlowResultType.ABORT | 
|  | 309 | +    assert result["reason"] == "reconfigure_successful" | 
|  | 310 | +    assert mock_config_entry.data[CONF_API_TOKEN] == "new_api_key" | 
|  | 311 | +    assert mock_config_entry.data[CONF_URL] == "https://new_domain:9000/" | 
|  | 312 | +    assert mock_config_entry.data[CONF_VERIFY_SSL] is True | 
|  | 313 | +    assert len(mock_setup_entry.mock_calls) == 1 | 
0 commit comments