Add config flow tests #4

Merged
mat merged 3 commits from test/config-flow into main 2026-04-24 12:38:29 +00:00
Owner

Summary

  • Adds tests/test_config_flow.py covering the user step: form render, happy path, invalid_auth (missing cwt_session cookie), cannot_connect (authenticate raises), and schema-level rejection when username / password are missing.

Depends on

  • #3 (test infrastructure). This branch is built on top of test/infra; the diff shown here will collapse to a single new file once #3 merges.

Test plan

  • pytest tests/test_config_flow.py — 6 passed locally
  • Re-verified once PR8 wires pytest into CI

Notes

  • The tests exercise current shipped behavior. Later PRs that change auth/error handling (finding C7 reauth flow, H5 narrower exception handling) will need to update these expectations — that's intentional, so regressions are caught.
## Summary - Adds `tests/test_config_flow.py` covering the user step: form render, happy path, `invalid_auth` (missing `cwt_session` cookie), `cannot_connect` (authenticate raises), and schema-level rejection when `username` / `password` are missing. ## Depends on - #3 (test infrastructure). This branch is built on top of `test/infra`; the diff shown here will collapse to a single new file once #3 merges. ## Test plan - [x] `pytest tests/test_config_flow.py` — 6 passed locally - [ ] Re-verified once PR8 wires pytest into CI ## Notes - The tests exercise current shipped behavior. Later PRs that change auth/error handling (finding C7 reauth flow, H5 narrower exception handling) will need to update these expectations — that's intentional, so regressions are caught.
(AI) Add pytest infrastructure
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
253d3d9515
Adds the plumbing needed to run Home Assistant custom-integration tests:

- `requirements-test.txt` pins `pytest-homeassistant-custom-component`
  (which transitively pulls `homeassistant`) and the runtime dependency
  `comwatt-client`.
- `pytest.ini` enables `asyncio_mode = auto` and points pytest at
  `tests/`.
- `tests/conftest.py` loads the pytest-homeassistant-custom-component
  plugin, auto-enables custom integrations, and exposes a
  `mock_comwatt_client` fixture that patches every import site of
  `ComwattClient` used by the integration.
- `tests/test_smoke.py` exercises the plumbing and asserts basic
  manifest/domain invariants.

Follow-up PRs will add config-flow, init, sensor, and switch tests on
top of this scaffolding.
🐛 (AI) Fix cookie jar mock in test fixture
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
05511bb47b
`_make_fake_client` assigned a plain list to `session.cookies` then
tried to attach a `get_dict` attribute to it, which fails because
lists don't accept arbitrary attributes. Introduce `_FakeCookieJar`, a
list subclass that answers `get_dict()` the way `requests`' own
`RequestsCookieJar` does, so both iteration (used by the config flow)
and `get_dict()` (used by the integration to snapshot the session)
work against the mock.
(AI) Add config flow tests
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
f212ea376d
Covers the user-facing config-flow step:

- Initial form rendering with no errors.
- Happy path: valid credentials create a config entry titled with the
  username, and `authenticate()` is called with those credentials.
- `invalid_auth` when `authenticate()` succeeds but no `cwt_session`
  cookie is present (mirrors current cookie-sniffing logic).
- `cannot_connect` when `authenticate()` raises.
- Schema-level rejection when `username` or `password` is missing.

These exercise the current behavior as-shipped; later PRs that change
the auth/error handling will need to update these expectations.
mat force-pushed test/config-flow from f212ea376d
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
to f4f83acd5c
Some checks failed
Validate / validate-hacs (push) Failing after 3s
Validate / validate-hassfest (push) Failing after 3s
Validate / validate-hacs (pull_request) Failing after 3s
Validate / validate-hassfest (pull_request) Failing after 3s
2026-04-24 12:25:24 +00:00
Compare
mat changed title from (AI) Add config flow tests to Add config flow tests 2026-04-24 12:25:49 +00:00
mat force-pushed test/config-flow from f4f83acd5c
Some checks failed
Validate / validate-hacs (push) Failing after 3s
Validate / validate-hassfest (push) Failing after 3s
Validate / validate-hacs (pull_request) Failing after 3s
Validate / validate-hassfest (pull_request) Failing after 3s
to dcaaec8ac9
All checks were successful
Validate / validate-hacs (push) Has been skipped
Validate / validate-hassfest (push) Has been skipped
Validate / validate-hacs (pull_request) Has been skipped
Validate / validate-hassfest (pull_request) Has been skipped
2026-04-24 12:36:51 +00:00
Compare
mat merged commit e561e57961 into main 2026-04-24 12:38:29 +00:00
mat deleted branch test/config-flow 2026-04-24 12:38:29 +00:00
mat referenced this pull request from a commit 2026-04-24 12:38:30 +00:00
mat referenced this pull request from a commit 2026-04-24 14:26:33 +00:00
mat referenced this pull request from a commit 2026-04-24 21:51:56 +00:00
mat referenced this pull request from a commit 2026-04-24 21:51:56 +00:00
mat referenced this pull request from a commit 2026-04-24 21:51:56 +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!4
No description provided.