♻️ Extract _submit_user_flow helper to collapse config-flow test boilerplate #44

Merged
mat merged 1 commit from config-flow-test-helper into main 2026-07-10 14:45:53 +00:00
Owner

Context

Flagged in the code review of #38 (Standards axis — "Duplicated Code") but skipped there to keep that fix PR tightly scoped.

Problem

The async_init / async_configure boilerplate for the user config flow is copy-pasted across 4 tests in tests/test_config_flow.py:

result = await hass.config_entries.flow.async_init(DOMAIN, context={"source": "user"})
result2 = await hass.config_entries.flow.async_configure(result["flow_id"], USER_INPUT)

Change

  • Extract _submit_user_flow(hass, user_input) -> FlowResult — starts the user flow, submits the input, returns the result.
  • Replace the boilerplate in the 4 user-flow tests (happy path, invalid auth, cannot connect, schema validation).
  • test_form_is_shown_first (init only, no submit) and the reauth tests (different start_reauth_flow shape) are left as-is.

Net: -8 lines, one source of truth for "submit the user flow".

Tests

29/29, ruff clean, mypy clean.

Interaction with #38

#38 adds test_cannot_connect_on_server_error, which also uses this boilerplate. Whichever PR merges first, the other needs a trivial rebase:

  • if this merges first → #38's new test should call _submit_user_flow (small conflict on tests/test_config_flow.py);
  • if #38 merges first → this PR rebases and collapses #38's new test too (no conflict, one more replacement).
## Context Flagged in the code review of #38 (Standards axis — "Duplicated Code") but skipped there to keep that fix PR tightly scoped. ## Problem The `async_init` / `async_configure` boilerplate for the user config flow is copy-pasted across 4 tests in `tests/test_config_flow.py`: ``` result = await hass.config_entries.flow.async_init(DOMAIN, context={"source": "user"}) result2 = await hass.config_entries.flow.async_configure(result["flow_id"], USER_INPUT) ``` ## Change - Extract `_submit_user_flow(hass, user_input) -> FlowResult` — starts the user flow, submits the input, returns the result. - Replace the boilerplate in the 4 user-flow tests (happy path, invalid auth, cannot connect, schema validation). - `test_form_is_shown_first` (init only, no submit) and the reauth tests (different `start_reauth_flow` shape) are left as-is. Net: -8 lines, one source of truth for "submit the user flow". ## Tests 29/29, ruff clean, mypy clean. ## Interaction with #38 #38 adds `test_cannot_connect_on_server_error`, which also uses this boilerplate. Whichever PR merges first, the other needs a trivial rebase: - if **this** merges first → #38's new test should call `_submit_user_flow` (small conflict on `tests/test_config_flow.py`); - if **#38** merges first → this PR rebases and collapses #38's new test too (no conflict, one more replacement).
♻️ Extract _submit_user_flow helper to collapse config-flow test boilerplate
All checks were successful
Validate / lint-ruff (push) Successful in 7s
Validate / test-pytest (push) Successful in 3m0s
Validate / type-check-mypy (push) Successful in 3m7s
Validate / lint-ruff (pull_request) Successful in 7s
Validate / test-pytest (pull_request) Successful in 2m59s
Validate / type-check-mypy (pull_request) Successful in 3m7s
c1c0162d8f
mat merged commit 14fee5e9f5 into main 2026-07-10 14:45:53 +00:00
mat deleted branch config-flow-test-helper 2026-07-10 14:45:53 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mat/homeassistant-comwatt!44
No description provided.