Skip to content

Commit cb6f4aa

Browse files
authored
Fix tests (#133)
* Update pytest-homeassistant-custom-component * Use FlowResultType in tests
1 parent 1d8983a commit cb6f4aa

File tree

3 files changed

+359
-293
lines changed

3 files changed

+359
-293
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ repository = "https://github.com/DeerMaximum/Technische-Alternative-CMI"
3333
[dependency-groups]
3434
dev = [
3535
"aiohttp_cors",
36-
"pytest-homeassistant-custom-component==0.13.232",
36+
"pytest-homeassistant-custom-component==0.13.252",
3737
"josepy<2.0.0"
3838
]
3939
lint = [

tests/test_config_flow.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from typing import Any
77
from unittest.mock import patch
88

9-
from homeassistant import data_entry_flow
9+
import pytest
1010
from homeassistant.config_entries import SOURCE_USER
1111
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
1212
from homeassistant.core import HomeAssistant
13-
import pytest
13+
from homeassistant.data_entry_flow import FlowResultType
1414
from pytest_homeassistant_custom_component.common import MockConfigEntry
1515
from ta_cmi import CMIAPI, ApiError, Device, InvalidCredentialsError, RateLimitError
1616

@@ -180,7 +180,7 @@ async def test_show_set_form(hass: HomeAssistant) -> None:
180180
DOMAIN, context={"source": SOURCE_USER}
181181
)
182182

183-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
183+
assert result["type"] == FlowResultType.FORM
184184
assert result["step_id"] == "user"
185185

186186

@@ -195,7 +195,7 @@ async def test_step_user_connection_error(hass: HomeAssistant) -> None:
195195
DOMAIN, context={"source": SOURCE_USER}, data=DUMMY_CONNECTION_DATA
196196
)
197197

198-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
198+
assert result["type"] == FlowResultType.FORM
199199
assert result["step_id"] == "user"
200200
assert result["errors"] == {"base": "cannot_connect"}
201201

@@ -211,7 +211,7 @@ async def test_step_user_invalid_auth(hass: HomeAssistant) -> None:
211211
DOMAIN, context={"source": SOURCE_USER}, data=DUMMY_CONNECTION_DATA
212212
)
213213

214-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
214+
assert result["type"] == FlowResultType.FORM
215215
assert result["step_id"] == "user"
216216
assert result["errors"] == {"base": "invalid_auth"}
217217

@@ -227,7 +227,7 @@ async def test_step_user_unexpected_exception(hass: HomeAssistant) -> None:
227227
DOMAIN, context={"source": SOURCE_USER}, data=DUMMY_CONNECTION_DATA
228228
)
229229

230-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
230+
assert result["type"] == FlowResultType.FORM
231231
assert result["step_id"] == "user"
232232
assert result["errors"] == {"base": "unknown"}
233233

@@ -249,7 +249,7 @@ async def test_step_user(hass: HomeAssistant) -> None:
249249

250250
sleep_m.assert_called_once()
251251

252-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
252+
assert result["type"] == FlowResultType.FORM
253253
assert result["step_id"] == "devices"
254254
assert result["errors"] == {}
255255

@@ -271,7 +271,7 @@ async def test_step_user_only_ip(hass: HomeAssistant) -> None:
271271

272272
sleep_m.assert_called_once()
273273

274-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
274+
assert result["type"] == FlowResultType.FORM
275275
assert result["step_id"] == "devices"
276276
assert result["errors"] == {}
277277

@@ -293,7 +293,7 @@ async def test_step_user_unkown_device(hass: HomeAssistant) -> None:
293293
DOMAIN, context={"source": SOURCE_USER}, data=DUMMY_CONNECTION_DATA
294294
)
295295

296-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
296+
assert result["type"] == FlowResultType.FORM
297297
assert result["step_id"] == "devices"
298298
assert result["errors"] == {"base": "unknown"}
299299

@@ -308,7 +308,7 @@ async def test_new_uid_flag_set(hass: HomeAssistant) -> None:
308308
data=DUMMY_DEVICE_DATA_NO_CHANNEL_FETCH_ALL,
309309
)
310310

311-
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
311+
assert result["type"] == FlowResultType.CREATE_ENTRY
312312
assert result["title"] == "C.M.I"
313313
assert result["data"][NEW_UID] == True
314314

@@ -324,7 +324,7 @@ async def test_step_devices_without_edit_fetch_all(hass: HomeAssistant) -> None:
324324
data=DUMMY_DEVICE_DATA_NO_CHANNEL_FETCH_ALL,
325325
)
326326

327-
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
327+
assert result["type"] == FlowResultType.CREATE_ENTRY
328328
assert result["title"] == "C.M.I"
329329

330330

@@ -344,7 +344,7 @@ async def test_step_devices_without_edit_fetch_defined(hass: HomeAssistant) -> N
344344
data=DUMMY_DEVICE_DATA_NO_CHANNEL_FETCH_DEFINED,
345345
)
346346

347-
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
347+
assert result["type"] == FlowResultType.CREATE_ENTRY
348348
assert result["title"] == "C.M.I"
349349

350350

@@ -378,7 +378,7 @@ async def test_step_device_with_device_without_io_support(hass: HomeAssistant) -
378378
assert sleep_m.call_count == 2
379379
assert request_m.call_count == 3
380380

381-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
381+
assert result["type"] == FlowResultType.FORM
382382
assert result["step_id"] == "devices"
383383
assert result["errors"] == {}
384384

@@ -400,7 +400,7 @@ async def test_step_devices_with_multiple_devices(hass: HomeAssistant) -> None:
400400
DOMAIN, context={"source": "devices"}
401401
)
402402

403-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
403+
assert result["type"] == FlowResultType.FORM
404404
assert result["step_id"] == "devices"
405405
assert result["errors"] == {"base": "unknown"}
406406

@@ -415,7 +415,7 @@ async def test_step_devices_with_edit(hass: HomeAssistant) -> None:
415415
data=DUMMY_DEVICE_DATA_EDIT_CHANNEL,
416416
)
417417

418-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
418+
assert result["type"] == FlowResultType.FORM
419419
assert result["step_id"] == "channel"
420420
assert result["errors"] == {}
421421

@@ -433,7 +433,7 @@ async def test_step_finish_dynamic_wait(hass: HomeAssistant) -> None:
433433
data=DUMMY_DEVICE_DATA_NO_CHANNEL_FETCH_DEFINED,
434434
)
435435

436-
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
436+
assert result["type"] == FlowResultType.CREATE_ENTRY
437437
assert result["title"] == "C.M.I"
438438

439439
mock.assert_called_once()
@@ -452,7 +452,7 @@ async def test_step_device_communication_error(hass: HomeAssistant) -> None:
452452
context={"source": "devices"},
453453
)
454454

455-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
455+
assert result["type"] == FlowResultType.FORM
456456
assert result["step_id"] == "devices"
457457
assert result["errors"] == {"base": "device_error"}
458458

@@ -470,7 +470,7 @@ async def test_step_device_unkown_error(hass: HomeAssistant) -> None:
470470
context={"source": "devices"},
471471
)
472472

473-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
473+
assert result["type"] == FlowResultType.FORM
474474
assert result["step_id"] == "devices"
475475
assert result["errors"] == {"base": "unknown"}
476476

@@ -488,7 +488,7 @@ async def test_step_device_rate_limit_error(hass: HomeAssistant) -> None:
488488
context={"source": "devices"},
489489
)
490490

491-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
491+
assert result["type"] == FlowResultType.FORM
492492
assert result["step_id"] == "devices"
493493
assert result["errors"] == {"base": "rate_limit"}
494494

@@ -516,7 +516,7 @@ async def test_step_channels_edit_only_one(hass: HomeAssistant) -> None:
516516
data=DUMMY_CHANNEL_DATA_NO_OTHER_EDIT,
517517
)
518518

519-
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
519+
assert result["type"] == FlowResultType.CREATE_ENTRY
520520
assert result["title"] == "C.M.I"
521521

522522

@@ -541,7 +541,7 @@ async def test_step_channels_edit_more(hass: HomeAssistant) -> None:
541541
DOMAIN, context={"source": "channel"}, data=DUMMY_CHANNEL_DATA_OTHER_EDIT
542542
)
543543

544-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
544+
assert result["type"] == FlowResultType.FORM
545545
assert result["step_id"] == "channel"
546546
assert result["errors"] == {}
547547

@@ -563,15 +563,15 @@ async def test_options_flow_init_no_ip(hass: HomeAssistant) -> None:
563563
await hass.config_entries.async_setup(config_entry.entry_id)
564564
await hass.async_block_till_done()
565565

566-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
566+
assert result["type"] == FlowResultType.FORM
567567
assert result["step_id"] == "init"
568568

569569
result = await hass.config_entries.options.async_configure(
570570
result["flow_id"],
571571
user_input=DUMMY_ENTRY_CHANGE,
572572
)
573573

574-
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
574+
assert result["type"] == FlowResultType.CREATE_ENTRY
575575
assert dict(config_entry.options) == DUMMY_CONFIG_ENTRY_UPDATED
576576

577577

@@ -598,15 +598,15 @@ async def test_options_flow_init(hass: HomeAssistant) -> None:
598598
await hass.config_entries.async_setup(config_entry.entry_id)
599599
await hass.async_block_till_done()
600600

601-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
601+
assert result["type"] == FlowResultType.FORM
602602
assert result["step_id"] == "init"
603603

604604
result = await hass.config_entries.options.async_configure(
605605
result["flow_id"],
606606
user_input=DUMMY_ENTRY_CHANGE_IP,
607607
)
608608

609-
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
609+
assert result["type"] == FlowResultType.CREATE_ENTRY
610610
assert dict(config_entry.options) == DUMMY_CONFIG_ENTRY_UPDATED_IP
611611

612612

@@ -629,15 +629,15 @@ async def test_options_flow_ip_change_invalid_auth(hass: HomeAssistant) -> None:
629629
await hass.config_entries.async_setup(config_entry.entry_id)
630630
await hass.async_block_till_done()
631631

632-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
632+
assert result["type"] == FlowResultType.FORM
633633
assert result["step_id"] == "init"
634634

635635
result = await hass.config_entries.options.async_configure(
636636
result["flow_id"],
637637
user_input=DUMMY_ENTRY_CHANGE_IP,
638638
)
639639

640-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
640+
assert result["type"] == FlowResultType.FORM
641641
assert result["step_id"] == "init"
642642
assert result["errors"] == {"base": "invalid_auth"}
643643
assert dict(config_entry.options) == {}
@@ -662,15 +662,15 @@ async def test_options_flow_ip_change_connection_error(hass: HomeAssistant) -> N
662662
await hass.config_entries.async_setup(config_entry.entry_id)
663663
await hass.async_block_till_done()
664664

665-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
665+
assert result["type"] == FlowResultType.FORM
666666
assert result["step_id"] == "init"
667667

668668
result = await hass.config_entries.options.async_configure(
669669
result["flow_id"],
670670
user_input=DUMMY_ENTRY_CHANGE_IP,
671671
)
672672

673-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
673+
assert result["type"] == FlowResultType.FORM
674674
assert result["step_id"] == "init"
675675
assert result["errors"] == {"base": "cannot_connect"}
676676
assert dict(config_entry.options) == {}
@@ -695,15 +695,15 @@ async def test_options_flow_ip_change_unexpected_error(hass: HomeAssistant) -> N
695695
await hass.config_entries.async_setup(config_entry.entry_id)
696696
await hass.async_block_till_done()
697697

698-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
698+
assert result["type"] == FlowResultType.FORM
699699
assert result["step_id"] == "init"
700700

701701
result = await hass.config_entries.options.async_configure(
702702
result["flow_id"],
703703
user_input=DUMMY_ENTRY_CHANGE_IP,
704704
)
705705

706-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
706+
assert result["type"] == FlowResultType.FORM
707707
assert result["step_id"] == "init"
708708
assert result["errors"] == {"base": "unknown"}
709709
assert dict(config_entry.options) == {}

0 commit comments

Comments
 (0)