Optimize optionflow tests (#74262)

* Optimize optionflow tests

* Extend mocking
This commit is contained in:
Maximilian 2022-06-30 19:45:11 +02:00 committed by GitHub
parent 2723ca0b85
commit dc22726425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -163,6 +163,9 @@ async def test_options_flow_init(hass: HomeAssistant) -> None:
"pynina.baseApi.BaseAPI._makeRequest",
wraps=mocked_request_function,
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
@ -213,6 +216,8 @@ async def test_options_flow_with_no_selection(hass: HomeAssistant) -> None:
"pynina.baseApi.BaseAPI._makeRequest",
wraps=mocked_request_function,
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(config_entry.entry_id)
@ -248,7 +253,12 @@ async def test_options_flow_connection_error(hass: HomeAssistant) -> None:
with patch(
"pynina.baseApi.BaseAPI._makeRequest",
side_effect=ApiError("Could not connect to Api"),
), patch(
"homeassistant.components.nina.async_setup_entry",
return_value=True,
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(config_entry.entry_id)
@ -268,7 +278,12 @@ async def test_options_flow_unexpected_exception(hass: HomeAssistant) -> None:
with patch(
"pynina.baseApi.BaseAPI._makeRequest",
side_effect=Exception("DUMMY"),
), patch(
"homeassistant.components.nina.async_setup_entry",
return_value=True,
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(config_entry.entry_id)