From 2542ddd30a4913ccc2213fc5456b969f6b6e4366 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:09:53 +0200 Subject: [PATCH] Improve check for user-visible flows when checking translations in tests (#128434) * Improve check for user-visible flows when checking translations in tests * Fix nest (from DHCP) * Ignore homeassistant_hardware * Improve logic --- homeassistant/components/nest/strings.json | 1 + tests/components/conftest.py | 16 ++++-- .../test_config_flow_failures.py | 52 +++++++++++++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/nest/strings.json b/homeassistant/components/nest/strings.json index 8e40bf27d1f..dd02818a0eb 100644 --- a/homeassistant/components/nest/strings.json +++ b/homeassistant/components/nest/strings.json @@ -45,6 +45,7 @@ "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_account%]", "missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]", + "missing_credentials": "[%key:common::config_flow::abort::oauth2_missing_credentials%]", "authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]", "unknown_authorize_url_generation": "[%key:common::config_flow::abort::unknown_authorize_url_generation%]", "no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]", diff --git a/tests/components/conftest.py b/tests/components/conftest.py index dcd537f9b32..12bf3ae7d4f 100644 --- a/tests/components/conftest.py +++ b/tests/components/conftest.py @@ -533,11 +533,17 @@ def check_config_translations(ignore_translations: str | list[str]) -> Generator else: return result - if ( - result["type"] is FlowResultType.ABORT - and flow.source != SOURCE_SYSTEM - and flow.source not in DISCOVERY_SOURCES - ): + # Check if this flow has been seen before + # Gets set to False on first run, and to True on subsequent runs + setattr(flow, "__flow_seen_before", hasattr(flow, "__flow_seen_before")) + + if result["type"] is FlowResultType.ABORT: + # We don't need translations for a discovery flow which immediately + # aborts, since such flows won't be seen by users + if not flow.__flow_seen_before and ( + flow.source == SOURCE_SYSTEM or flow.source in DISCOVERY_SOURCES + ): + return result await _ensure_translation_exists( flow.hass, _ignore_translations, diff --git a/tests/components/homeassistant_hardware/test_config_flow_failures.py b/tests/components/homeassistant_hardware/test_config_flow_failures.py index 936363daaea..ca40d46a437 100644 --- a/tests/components/homeassistant_hardware/test_config_flow_failures.py +++ b/tests/components/homeassistant_hardware/test_config_flow_failures.py @@ -30,6 +30,10 @@ async def fixture_mock_supervisor_client(supervisor_client: AsyncMock): """Mock supervisor client in tests.""" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.unsupported_firmware"], +) @pytest.mark.parametrize( "next_step", [ @@ -60,6 +64,10 @@ async def test_config_flow_cannot_probe_firmware( assert result["reason"] == "unsupported_firmware" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.not_hassio"], +) async def test_config_flow_zigbee_not_hassio_wrong_firmware( hass: HomeAssistant, ) -> None: @@ -85,6 +93,10 @@ async def test_config_flow_zigbee_not_hassio_wrong_firmware( assert result["reason"] == "not_hassio" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.addon_already_running"], +) async def test_config_flow_zigbee_flasher_addon_already_running( hass: HomeAssistant, ) -> None: @@ -119,6 +131,10 @@ async def test_config_flow_zigbee_flasher_addon_already_running( assert result["reason"] == "addon_already_running" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.addon_info_failed"], +) async def test_config_flow_zigbee_flasher_addon_info_fails(hass: HomeAssistant) -> None: """Test failure case when flasher addon cannot be installed.""" result = await hass.config_entries.flow.async_init( @@ -152,6 +168,10 @@ async def test_config_flow_zigbee_flasher_addon_info_fails(hass: HomeAssistant) assert result["reason"] == "addon_info_failed" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.addon_install_failed"], +) async def test_config_flow_zigbee_flasher_addon_install_fails( hass: HomeAssistant, ) -> None: @@ -182,6 +202,10 @@ async def test_config_flow_zigbee_flasher_addon_install_fails( assert result["reason"] == "addon_install_failed" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.addon_set_config_failed"], +) async def test_config_flow_zigbee_flasher_addon_set_config_fails( hass: HomeAssistant, ) -> None: @@ -216,6 +240,10 @@ async def test_config_flow_zigbee_flasher_addon_set_config_fails( assert result["reason"] == "addon_set_config_failed" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.addon_start_failed"], +) async def test_config_flow_zigbee_flasher_run_fails(hass: HomeAssistant) -> None: """Test failure case when flasher addon fails to run.""" result = await hass.config_entries.flow.async_init( @@ -277,6 +305,10 @@ async def test_config_flow_zigbee_flasher_uninstall_fails(hass: HomeAssistant) - assert result["step_id"] == "confirm_zigbee" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.not_hassio_thread"], +) async def test_config_flow_thread_not_hassio(hass: HomeAssistant) -> None: """Test when the stick is used with a non-hassio setup and Thread is selected.""" result = await hass.config_entries.flow.async_init( @@ -300,6 +332,10 @@ async def test_config_flow_thread_not_hassio(hass: HomeAssistant) -> None: assert result["reason"] == "not_hassio_thread" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.addon_info_failed"], +) async def test_config_flow_thread_addon_info_fails(hass: HomeAssistant) -> None: """Test failure case when flasher addon cannot be installed.""" result = await hass.config_entries.flow.async_init( @@ -324,6 +360,10 @@ async def test_config_flow_thread_addon_info_fails(hass: HomeAssistant) -> None: assert result["reason"] == "addon_info_failed" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.otbr_addon_already_running"], +) async def test_config_flow_thread_addon_already_running(hass: HomeAssistant) -> None: """Test failure case when the Thread addon is already running.""" result = await hass.config_entries.flow.async_init( @@ -359,6 +399,10 @@ async def test_config_flow_thread_addon_already_running(hass: HomeAssistant) -> assert result["reason"] == "otbr_addon_already_running" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.addon_install_failed"], +) async def test_config_flow_thread_addon_install_fails(hass: HomeAssistant) -> None: """Test failure case when flasher addon cannot be installed.""" result = await hass.config_entries.flow.async_init( @@ -386,6 +430,10 @@ async def test_config_flow_thread_addon_install_fails(hass: HomeAssistant) -> No assert result["reason"] == "addon_install_failed" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.addon_set_config_failed"], +) async def test_config_flow_thread_addon_set_config_fails(hass: HomeAssistant) -> None: """Test failure case when flasher addon cannot be configured.""" result = await hass.config_entries.flow.async_init( @@ -413,6 +461,10 @@ async def test_config_flow_thread_addon_set_config_fails(hass: HomeAssistant) -> assert result["reason"] == "addon_set_config_failed" +@pytest.mark.parametrize( + "ignore_translations", + ["component.test_firmware_domain.config.abort.addon_start_failed"], +) async def test_config_flow_thread_flasher_run_fails(hass: HomeAssistant) -> None: """Test failure case when flasher addon fails to run.""" result = await hass.config_entries.flow.async_init(