1010 OAUTH2_AUTHORIZE ,
1111 OAUTH2_TOKEN ,
1212)
13- from homeassistant .config_entries import SOURCE_DHCP
13+ from homeassistant .config_entries import SOURCE_DHCP , SOURCE_USER
1414from homeassistant .core import HomeAssistant
1515from homeassistant .data_entry_flow import FlowResultType
1616from homeassistant .helpers import config_entry_oauth2_flow
2323from tests .typing import ClientSessionGenerator
2424
2525
26+ @pytest .fixture
27+ def use_cloud (hass : HomeAssistant ) -> None :
28+ """Set up the cloud component."""
29+ hass .config .components .add ("cloud" )
30+
31+
2632@pytest .fixture
2733async def access_token (hass : HomeAssistant ) -> str :
2834 """Return a valid access token with sub field for unique ID."""
@@ -37,7 +43,7 @@ async def access_token(hass: HomeAssistant) -> str:
3743 )
3844
3945
40- @pytest .mark .usefixtures ("current_request_with_host" )
46+ @pytest .mark .usefixtures ("current_request_with_host" , "use_cloud" )
4147async def test_full_flow (
4248 hass : HomeAssistant ,
4349 hass_client_no_auth : ClientSessionGenerator ,
@@ -97,7 +103,7 @@ async def test_full_flow(
97103 assert result ["result" ].unique_id == USER_ID
98104
99105
100- @pytest .mark .usefixtures ("current_request_with_host" )
106+ @pytest .mark .usefixtures ("current_request_with_host" , "use_cloud" )
101107async def test_full_dhcp_flow (
102108 hass : HomeAssistant ,
103109 hass_client_no_auth : ClientSessionGenerator ,
@@ -170,7 +176,7 @@ async def test_full_dhcp_flow(
170176 assert result ["result" ].unique_id == USER_ID
171177
172178
173- @pytest .mark .usefixtures ("current_request_with_host" )
179+ @pytest .mark .usefixtures ("current_request_with_host" , "use_cloud" )
174180async def test_duplicate_entry (
175181 hass : HomeAssistant ,
176182 hass_client_no_auth : ClientSessionGenerator ,
@@ -221,7 +227,7 @@ async def test_duplicate_entry(
221227 assert result ["reason" ] == "already_configured"
222228
223229
224- @pytest .mark .usefixtures ("current_request_with_host" )
230+ @pytest .mark .usefixtures ("current_request_with_host" , "use_cloud" )
225231async def test_duplicate_dhcp_entry (
226232 hass : HomeAssistant ,
227233 hass_client_no_auth : ClientSessionGenerator ,
@@ -243,7 +249,7 @@ async def test_duplicate_dhcp_entry(
243249 assert result ["reason" ] == "already_configured"
244250
245251
246- @pytest .mark .usefixtures ("current_request_with_host" )
252+ @pytest .mark .usefixtures ("current_request_with_host" , "use_cloud" )
247253async def test_flow_reauth (
248254 hass : HomeAssistant ,
249255 hass_client_no_auth : ClientSessionGenerator ,
@@ -306,7 +312,7 @@ async def test_flow_reauth(
306312 assert len (hass .config_entries .async_entries (DOMAIN )) == 1
307313
308314
309- @pytest .mark .usefixtures ("current_request_with_host" )
315+ @pytest .mark .usefixtures ("current_request_with_host" , "use_cloud" )
310316async def test_flow_wrong_account_reauth (
311317 hass : HomeAssistant ,
312318 hass_client_no_auth : ClientSessionGenerator ,
@@ -370,3 +376,39 @@ async def test_flow_wrong_account_reauth(
370376 # Should abort with wrong account
371377 assert result ["type" ] == "abort"
372378 assert result ["reason" ] == "wrong_account"
379+
380+
381+ @pytest .mark .usefixtures ("current_request_with_host" )
382+ async def test_no_cloud (
383+ hass : HomeAssistant ,
384+ hass_client_no_auth : ClientSessionGenerator ,
385+ aioclient_mock : AiohttpClientMocker ,
386+ ) -> None :
387+ """Check we abort when cloud is not enabled."""
388+ result = await hass .config_entries .flow .async_init (
389+ DOMAIN , context = {"source" : SOURCE_USER }
390+ )
391+
392+ assert result ["type" ] is FlowResultType .ABORT
393+ assert result ["reason" ] == "cloud_not_enabled"
394+
395+
396+ @pytest .mark .usefixtures ("current_request_with_host" )
397+ async def test_reauthentication_no_cloud (
398+ hass : HomeAssistant ,
399+ hass_client_no_auth : ClientSessionGenerator ,
400+ aioclient_mock : AiohttpClientMocker ,
401+ mock_config_entry : MockConfigEntry ,
402+ ) -> None :
403+ """Test Aladdin Connect reauthentication without cloud."""
404+ mock_config_entry .add_to_hass (hass )
405+
406+ result = await mock_config_entry .start_reauth_flow (hass )
407+
408+ assert result ["type" ] is FlowResultType .FORM
409+ assert result ["step_id" ] == "reauth_confirm"
410+
411+ result = await hass .config_entries .flow .async_configure (result ["flow_id" ], {})
412+
413+ assert result ["type" ] is FlowResultType .ABORT
414+ assert result ["reason" ] == "cloud_not_enabled"
0 commit comments