Skip to content

Commit

Permalink
Use mock_config_flow helper in config tests (home-assistant#117245)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored and dgomes committed May 11, 2024
1 parent 8ec5cca commit 148eb99
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions tests/components/config/test_config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
MockConfigEntry,
MockModule,
MockUser,
mock_config_flow,
mock_integration,
mock_platform,
)
Expand Down Expand Up @@ -49,7 +50,25 @@ async def client(hass, hass_client) -> TestClient:
return await hass_client()


async def test_get_entries(hass: HomeAssistant, client, clear_handlers) -> None:
@pytest.fixture
async def mock_flow():
"""Mock a config flow."""

class Comp1ConfigFlow(ConfigFlow):
"""Config flow with options flow."""

@staticmethod
@callback
def async_get_options_flow(config_entry):
"""Get options flow."""

with mock_config_flow("comp1", Comp1ConfigFlow):
yield


async def test_get_entries(
hass: HomeAssistant, client, clear_handlers, mock_flow
) -> None:
"""Test get entries."""
mock_integration(hass, MockModule("comp1"))
mock_integration(
Expand All @@ -65,21 +84,6 @@ async def test_get_entries(hass: HomeAssistant, client, clear_handlers) -> None:
hass, MockModule("comp5", partial_manifest={"integration_type": "service"})
)

@HANDLERS.register("comp1")
class Comp1ConfigFlow:
"""Config flow with options flow."""

@staticmethod
@callback
def async_get_options_flow(config_entry):
"""Get options flow."""

@classmethod
@callback
def async_supports_options_flow(cls, config_entry):
"""Return options flow support for this handler."""
return True

config_entry_flow.register_discovery_flow("comp2", "Comp 2", lambda: None)

entry = MockConfigEntry(
Expand Down

0 comments on commit 148eb99

Please sign in to comment.