77 PortainerConnectionError ,
88 PortainerTimeoutError ,
99)
10+ from pyportainer .models .portainer import PortainerSystemStatus
1011import pytest
1112
1213from homeassistant .components .portainer .const import DOMAIN
@@ -81,7 +82,7 @@ async def test_form_exceptions(
8182 reason : str ,
8283) -> None :
8384 """Test we handle all exceptions."""
84- mock_portainer_client .get_endpoints .side_effect = exception
85+ mock_portainer_client .portainer_system_status .side_effect = exception
8586
8687 result = await hass .config_entries .flow .async_init (
8788 DOMAIN , context = {"source" : SOURCE_USER }
@@ -98,7 +99,7 @@ async def test_form_exceptions(
9899 assert result ["type" ] is FlowResultType .FORM
99100 assert result ["errors" ] == {"base" : reason }
100101
101- mock_portainer_client .get_endpoints .side_effect = None
102+ mock_portainer_client .portainer_system_status .side_effect = None
102103
103104 result = await hass .config_entries .flow .async_configure (
104105 result ["flow_id" ],
@@ -199,7 +200,7 @@ async def test_reauth_flow_exceptions(
199200 """Test we handle all exceptions in the reauth flow."""
200201 mock_config_entry .add_to_hass (hass )
201202
202- mock_portainer_client .get_endpoints .side_effect = exception
203+ mock_portainer_client .portainer_system_status .side_effect = exception
203204
204205 result = await hass .config_entries .flow .async_init (
205206 DOMAIN , context = {"source" : SOURCE_USER }
@@ -216,7 +217,7 @@ async def test_reauth_flow_exceptions(
216217 assert result ["errors" ] == {"base" : reason }
217218
218219 # Now test that we can recover from the error
219- mock_portainer_client .get_endpoints .side_effect = None
220+ mock_portainer_client .portainer_system_status .side_effect = None
220221
221222 result = await hass .config_entries .flow .async_configure (
222223 result ["flow_id" ],
@@ -255,23 +256,17 @@ async def test_full_flow_reconfigure(
255256 assert len (mock_setup_entry .mock_calls ) == 1
256257
257258
258- async def test_full_flow_reconfigure_unique_id (
259+ async def test_full_flow_reconfigure_unique_id_mismatch (
259260 hass : HomeAssistant ,
260261 mock_portainer_client : AsyncMock ,
261262 mock_setup_entry : MagicMock ,
262263 mock_config_entry : MockConfigEntry ,
263264) -> None :
264- """Test the full flow of the config flow, this time with a known unique ID ."""
265+ """Test reconfigure aborts when credentials point to a different Portainer instance ."""
265266 mock_config_entry .add_to_hass (hass )
266-
267- other_entry = MockConfigEntry (
268- domain = DOMAIN ,
269- title = "Portainer other" ,
270- data = USER_INPUT_RECONFIGURE ,
271- unique_id = USER_INPUT_RECONFIGURE [CONF_API_TOKEN ],
267+ mock_portainer_client .portainer_system_status .return_value = PortainerSystemStatus (
268+ instance_id = "different-instance-id" , version = "2.0.0"
272269 )
273- other_entry .add_to_hass (hass )
274-
275270 result = await mock_config_entry .start_reconfigure_flow (hass )
276271 assert result ["type" ] is FlowResultType .FORM
277272 assert result ["step_id" ] == "reconfigure"
@@ -282,7 +277,7 @@ async def test_full_flow_reconfigure_unique_id(
282277 )
283278
284279 assert result ["type" ] is FlowResultType .ABORT
285- assert result ["reason" ] == "already_configured "
280+ assert result ["reason" ] == "unique_id_mismatch "
286281 assert mock_config_entry .data [CONF_API_TOKEN ] == "test_api_token"
287282 assert mock_config_entry .data [CONF_URL ] == "https://127.0.0.1:9000/"
288283 assert len (mock_setup_entry .mock_calls ) == 0
@@ -323,7 +318,7 @@ async def test_full_flow_reconfigure_exceptions(
323318 assert result ["type" ] is FlowResultType .FORM
324319 assert result ["step_id" ] == "reconfigure"
325320
326- mock_portainer_client .get_endpoints .side_effect = exception
321+ mock_portainer_client .portainer_system_status .side_effect = exception
327322 result = await hass .config_entries .flow .async_configure (
328323 result ["flow_id" ],
329324 user_input = USER_INPUT_RECONFIGURE ,
@@ -332,7 +327,7 @@ async def test_full_flow_reconfigure_exceptions(
332327 assert result ["type" ] is FlowResultType .FORM
333328 assert result ["errors" ] == {"base" : reason }
334329
335- mock_portainer_client .get_endpoints .side_effect = None
330+ mock_portainer_client .portainer_system_status .side_effect = None
336331 result = await hass .config_entries .flow .async_configure (
337332 result ["flow_id" ],
338333 user_input = USER_INPUT_RECONFIGURE ,
0 commit comments