22
33from unittest .mock import MagicMock , patch
44
5- from homeassistant .components import datadog
6- from homeassistant .config_entries import SOURCE_IMPORT , SOURCE_USER
7- from homeassistant .core import DOMAIN as HOMEASSISTANT_DOMAIN , HomeAssistant
5+ from homeassistant .components . datadog . const import DOMAIN
6+ from homeassistant .config_entries import SOURCE_USER
7+ from homeassistant .core import HomeAssistant
88from homeassistant .data_entry_flow import FlowResultType
9- import homeassistant .helpers .issue_registry as ir
109
11- from .common import MOCK_CONFIG , MOCK_DATA , MOCK_OPTIONS , MOCK_YAML_INVALID
10+ from .common import MOCK_CONFIG , MOCK_DATA , MOCK_OPTIONS
1211
1312from tests .common import MockConfigEntry
1413
@@ -22,7 +21,7 @@ async def test_user_flow_success(hass: HomeAssistant) -> None:
2221 mock_dogstatsd .return_value = mock_instance
2322
2423 result = await hass .config_entries .flow .async_init (
25- datadog . DOMAIN , context = {"source" : SOURCE_USER }
24+ DOMAIN , context = {"source" : SOURCE_USER }
2625 )
2726 assert result ["type" ] is FlowResultType .FORM
2827
@@ -42,7 +41,7 @@ async def test_user_flow_retry_after_connection_fail(hass: HomeAssistant) -> Non
4241 side_effect = OSError ("Connection failed" ),
4342 ):
4443 result = await hass .config_entries .flow .async_init (
45- datadog . DOMAIN , context = {"source" : SOURCE_USER }
44+ DOMAIN , context = {"source" : SOURCE_USER }
4645 )
4746
4847 result2 = await hass .config_entries .flow .async_configure (
@@ -67,14 +66,14 @@ async def test_user_flow_abort_already_configured_service(
6766) -> None :
6867 """Abort user-initiated config flow if the same host/port is already configured."""
6968 existing_entry = MockConfigEntry (
70- domain = datadog . DOMAIN ,
69+ domain = DOMAIN ,
7170 data = MOCK_DATA ,
7271 options = MOCK_OPTIONS ,
7372 )
7473 existing_entry .add_to_hass (hass )
7574
7675 result = await hass .config_entries .flow .async_init (
77- datadog . DOMAIN ,
76+ DOMAIN ,
7877 context = {"source" : SOURCE_USER },
7978 )
8079
@@ -93,7 +92,7 @@ async def test_user_flow_abort_already_configured_service(
9392async def test_options_flow_cannot_connect (hass : HomeAssistant ) -> None :
9493 """Test that the options flow shows an error when connection fails."""
9594 mock_entry = MockConfigEntry (
96- domain = datadog . DOMAIN ,
95+ domain = DOMAIN ,
9796 data = MOCK_DATA ,
9897 options = MOCK_OPTIONS ,
9998 )
@@ -123,67 +122,10 @@ async def test_options_flow_cannot_connect(hass: HomeAssistant) -> None:
123122 assert result3 ["data" ] == MOCK_OPTIONS
124123
125124
126- async def test_import_flow (
127- hass : HomeAssistant , issue_registry : ir .IssueRegistry
128- ) -> None :
129- """Test import triggers config flow and is accepted."""
130- with (
131- patch (
132- "homeassistant.components.datadog.config_flow.DogStatsd"
133- ) as mock_dogstatsd ,
134- ):
135- mock_instance = MagicMock ()
136- mock_dogstatsd .return_value = mock_instance
137-
138- result = await hass .config_entries .flow .async_init (
139- datadog .DOMAIN ,
140- context = {"source" : SOURCE_IMPORT },
141- data = MOCK_CONFIG ,
142- )
143-
144- assert result ["type" ] is FlowResultType .CREATE_ENTRY
145- assert result ["data" ] == MOCK_DATA
146- assert result ["options" ] == MOCK_OPTIONS
147-
148- await hass .async_block_till_done ()
149-
150- # Deprecation issue should be created
151- issue = issue_registry .async_get_issue (
152- HOMEASSISTANT_DOMAIN , "deprecated_yaml_datadog"
153- )
154- assert issue is not None
155- assert issue .translation_key == "deprecated_yaml"
156- assert issue .severity == ir .IssueSeverity .WARNING
157-
158-
159- async def test_import_connection_error (
160- hass : HomeAssistant , issue_registry : ir .IssueRegistry
161- ) -> None :
162- """Test import triggers connection error issue."""
163- with patch (
164- "homeassistant.components.datadog.config_flow.DogStatsd" ,
165- side_effect = OSError ("connection refused" ),
166- ):
167- result = await hass .config_entries .flow .async_init (
168- datadog .DOMAIN ,
169- context = {"source" : SOURCE_IMPORT },
170- data = MOCK_YAML_INVALID ,
171- )
172- assert result ["type" ] == "abort"
173- assert result ["reason" ] == "cannot_connect"
174-
175- issue = issue_registry .async_get_issue (
176- datadog .DOMAIN , "deprecated_yaml_import_connection_error"
177- )
178- assert issue is not None
179- assert issue .translation_key == "deprecated_yaml_import_connection_error"
180- assert issue .severity == ir .IssueSeverity .WARNING
181-
182-
183125async def test_options_flow (hass : HomeAssistant ) -> None :
184126 """Test updating options after setup."""
185127 mock_entry = MockConfigEntry (
186- domain = datadog . DOMAIN ,
128+ domain = DOMAIN ,
187129 data = MOCK_DATA ,
188130 options = MOCK_OPTIONS ,
189131 )
@@ -234,24 +176,3 @@ async def test_options_flow(hass: HomeAssistant) -> None:
234176 assert result ["type" ] is FlowResultType .CREATE_ENTRY
235177 assert result ["data" ] == new_options
236178 mock_instance .increment .assert_called_once_with ("connection_test" )
237-
238-
239- async def test_import_flow_abort_already_configured_service (
240- hass : HomeAssistant ,
241- ) -> None :
242- """Abort import if the same host/port is already configured."""
243- existing_entry = MockConfigEntry (
244- domain = datadog .DOMAIN ,
245- data = MOCK_DATA ,
246- options = MOCK_OPTIONS ,
247- )
248- existing_entry .add_to_hass (hass )
249-
250- result = await hass .config_entries .flow .async_init (
251- datadog .DOMAIN ,
252- context = {"source" : SOURCE_IMPORT },
253- data = MOCK_CONFIG ,
254- )
255-
256- assert result ["type" ] is FlowResultType .ABORT
257- assert result ["reason" ] == "already_configured"
0 commit comments