Skip to content

Commit

Permalink
Improve check for user-visible flows when checking translations in te…
Browse files Browse the repository at this point in the history
…sts (home-assistant#128434)

* Improve check for user-visible flows when checking translations in tests

* Fix nest (from DHCP)

* Ignore homeassistant_hardware

* Improve logic
  • Loading branch information
epenet authored Oct 15, 2024
1 parent 260d919 commit 2542ddd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
1 change: 1 addition & 0 deletions homeassistant/components/nest/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%]",
Expand Down
16 changes: 11 additions & 5 deletions tests/components/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,17 @@ async def _async_handle_step(
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2542ddd

Please sign in to comment.