Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mock_config_flow helper in config tests #117245

Merged
merged 1 commit into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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