Add check for valid abort reason translation in option flows (#128444)

This commit is contained in:
epenet 2024-10-16 13:41:15 +02:00 committed by GitHub
parent f7897bbd64
commit c5046f7809
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 69 additions and 0 deletions

View File

@ -15,6 +15,7 @@ from homeassistant.config_entries import (
DISCOVERY_SOURCES, DISCOVERY_SOURCES,
ConfigEntriesFlowManager, ConfigEntriesFlowManager,
FlowResult, FlowResult,
OptionsFlowManager,
) )
from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -529,6 +530,9 @@ def check_config_translations(ignore_translations: str | list[str]) -> Generator
if isinstance(self, ConfigEntriesFlowManager): if isinstance(self, ConfigEntriesFlowManager):
category = "config" category = "config"
component = flow.handler component = flow.handler
elif isinstance(self, OptionsFlowManager):
category = "options"
component = flow.hass.config_entries.async_get_entry(flow.handler).domain
else: else:
return result return result

View File

@ -526,6 +526,10 @@ async def test_config_flow_thread_flasher_uninstall_fails(hass: HomeAssistant) -
assert result["step_id"] == "confirm_otbr" assert result["step_id"] == "confirm_otbr"
@pytest.mark.parametrize(
"ignore_translations",
["component.test_firmware_domain.options.abort.zha_still_using_stick"],
)
async def test_options_flow_zigbee_to_thread_zha_configured( async def test_options_flow_zigbee_to_thread_zha_configured(
hass: HomeAssistant, hass: HomeAssistant,
) -> None: ) -> None:
@ -563,6 +567,10 @@ async def test_options_flow_zigbee_to_thread_zha_configured(
assert result["reason"] == "zha_still_using_stick" assert result["reason"] == "zha_still_using_stick"
@pytest.mark.parametrize(
"ignore_translations",
["component.test_firmware_domain.options.abort.otbr_still_using_stick"],
)
async def test_options_flow_thread_to_zigbee_otbr_configured( async def test_options_flow_thread_to_zigbee_otbr_configured(
hass: HomeAssistant, hass: HomeAssistant,
) -> None: ) -> None:

View File

@ -453,6 +453,10 @@ async def test_option_flow_install_multi_pan_addon_zha_other_radio(
} }
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.not_hassio"],
)
async def test_option_flow_non_hassio( async def test_option_flow_non_hassio(
hass: HomeAssistant, hass: HomeAssistant,
) -> None: ) -> None:
@ -765,6 +769,10 @@ async def test_option_flow_addon_installed_same_device_do_not_uninstall_multi_pa
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.addon_already_running"],
)
async def test_option_flow_flasher_already_running_failure( async def test_option_flow_flasher_already_running_failure(
hass: HomeAssistant, hass: HomeAssistant,
addon_info, addon_info,
@ -876,6 +884,10 @@ async def test_option_flow_addon_installed_same_device_flasher_already_installed
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.addon_install_failed"],
)
async def test_option_flow_flasher_install_failure( async def test_option_flow_flasher_install_failure(
hass: HomeAssistant, hass: HomeAssistant,
addon_info, addon_info,
@ -942,6 +954,10 @@ async def test_option_flow_flasher_install_failure(
assert result["reason"] == "addon_install_failed" assert result["reason"] == "addon_install_failed"
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.addon_start_failed"],
)
async def test_option_flow_flasher_addon_flash_failure( async def test_option_flow_flasher_addon_flash_failure(
hass: HomeAssistant, hass: HomeAssistant,
addon_info, addon_info,
@ -1004,6 +1020,10 @@ async def test_option_flow_flasher_addon_flash_failure(
assert result["description_placeholders"]["addon_name"] == "Silicon Labs Flasher" assert result["description_placeholders"]["addon_name"] == "Silicon Labs Flasher"
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.zha_migration_failed"],
)
@patch( @patch(
"homeassistant.components.zha.radio_manager.ZhaMultiPANMigrationHelper.async_initiate_migration", "homeassistant.components.zha.radio_manager.ZhaMultiPANMigrationHelper.async_initiate_migration",
side_effect=Exception("Boom!"), side_effect=Exception("Boom!"),
@ -1065,6 +1085,10 @@ async def test_option_flow_uninstall_migration_initiate_failure(
mock_initiate_migration.assert_called_once() mock_initiate_migration.assert_called_once()
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.zha_migration_failed"],
)
@patch( @patch(
"homeassistant.components.zha.radio_manager.ZhaMultiPANMigrationHelper.async_finish_migration", "homeassistant.components.zha.radio_manager.ZhaMultiPANMigrationHelper.async_finish_migration",
side_effect=Exception("Boom!"), side_effect=Exception("Boom!"),
@ -1166,6 +1190,10 @@ async def test_option_flow_do_not_install_multi_pan_addon(
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.addon_install_failed"],
)
async def test_option_flow_install_multi_pan_addon_install_fails( async def test_option_flow_install_multi_pan_addon_install_fails(
hass: HomeAssistant, hass: HomeAssistant,
addon_store_info, addon_store_info,
@ -1209,6 +1237,10 @@ async def test_option_flow_install_multi_pan_addon_install_fails(
assert result["reason"] == "addon_install_failed" assert result["reason"] == "addon_install_failed"
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.addon_start_failed"],
)
async def test_option_flow_install_multi_pan_addon_start_fails( async def test_option_flow_install_multi_pan_addon_start_fails(
hass: HomeAssistant, hass: HomeAssistant,
addon_store_info, addon_store_info,
@ -1271,6 +1303,10 @@ async def test_option_flow_install_multi_pan_addon_start_fails(
assert result["reason"] == "addon_start_failed" assert result["reason"] == "addon_start_failed"
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.addon_set_config_failed"],
)
async def test_option_flow_install_multi_pan_addon_set_options_fails( async def test_option_flow_install_multi_pan_addon_set_options_fails(
hass: HomeAssistant, hass: HomeAssistant,
addon_store_info, addon_store_info,
@ -1314,6 +1350,10 @@ async def test_option_flow_install_multi_pan_addon_set_options_fails(
assert result["reason"] == "addon_set_config_failed" assert result["reason"] == "addon_set_config_failed"
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.addon_info_failed"],
)
async def test_option_flow_addon_info_fails( async def test_option_flow_addon_info_fails(
hass: HomeAssistant, hass: HomeAssistant,
addon_store_info, addon_store_info,
@ -1337,6 +1377,10 @@ async def test_option_flow_addon_info_fails(
assert result["reason"] == "addon_info_failed" assert result["reason"] == "addon_info_failed"
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.zha_migration_failed"],
)
@patch( @patch(
"homeassistant.components.zha.radio_manager.ZhaMultiPANMigrationHelper.async_initiate_migration", "homeassistant.components.zha.radio_manager.ZhaMultiPANMigrationHelper.async_initiate_migration",
side_effect=Exception("Boom!"), side_effect=Exception("Boom!"),
@ -1392,6 +1436,10 @@ async def test_option_flow_install_multi_pan_addon_zha_migration_fails_step_1(
set_addon_options.assert_not_called() set_addon_options.assert_not_called()
@pytest.mark.parametrize(
"ignore_translations",
["component.test.options.abort.zha_migration_failed"],
)
@patch( @patch(
"homeassistant.components.zha.radio_manager.ZhaMultiPANMigrationHelper.async_finish_migration", "homeassistant.components.zha.radio_manager.ZhaMultiPANMigrationHelper.async_finish_migration",
side_effect=Exception("Boom!"), side_effect=Exception("Boom!"),

View File

@ -9,6 +9,7 @@ from typing import Any
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
from hyperion import const from hyperion import const
import pytest
from homeassistant.components import ssdp from homeassistant.components import ssdp
from homeassistant.components.hyperion.const import ( from homeassistant.components.hyperion.const import (
@ -823,6 +824,10 @@ async def test_options_effect_show_list(hass: HomeAssistant) -> None:
assert result["data"][CONF_EFFECT_HIDE_LIST] == ["effect2"] assert result["data"][CONF_EFFECT_HIDE_LIST] == ["effect2"]
@pytest.mark.parametrize( # Remove when translations fixed
"ignore_translations",
["component.hyperion.options.abort.cannot_connect"],
)
async def test_options_effect_hide_list_cannot_connect(hass: HomeAssistant) -> None: async def test_options_effect_hide_list_cannot_connect(hass: HomeAssistant) -> None:
"""Check an options flow effect hide list with a failed connection.""" """Check an options flow effect hide list with a failed connection."""

View File

@ -253,6 +253,10 @@ async def test_user_options_set_multiple(
) )
@pytest.mark.parametrize( # Remove when translations fixed
"ignore_translations",
["component.onewire.options.abort.No configurable devices found."],
)
async def test_user_options_no_devices( async def test_user_options_no_devices(
hass: HomeAssistant, config_entry: ConfigEntry hass: HomeAssistant, config_entry: ConfigEntry
) -> None: ) -> None: