Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions homeassistant/components/teslemetry/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ rules:
Multiline lambdas should be wrapped in parentheses for readability (e.g. streaming_listener).
Use chained comparison: "if 1 < x < 100" instead of "if x > 1 and x < 100".
config-flow: done
config-flow-test-coverage:
status: todo
comment: Use mock_setup_entry fixture instead of inline patch
config-flow-test-coverage: done
dependency-transparency: done
docs-actions: done
docs-high-level-description: done
Expand Down
26 changes: 8 additions & 18 deletions tests/components/teslemetry/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ async def test_reauth(


@pytest.mark.usefixtures("current_request_with_host")
@pytest.mark.usefixtures("mock_setup_entry")
async def test_reauth_account_mismatch(
hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator,
Expand All @@ -170,11 +171,8 @@ async def test_reauth_account_mismatch(
old_entry.add_to_hass(hass)

# Setup the integration properly to import client credentials
with patch(
"homeassistant.components.teslemetry.async_setup_entry", return_value=True
):
await hass.config_entries.async_setup(old_entry.entry_id)
await hass.async_block_till_done()
await hass.config_entries.async_setup(old_entry.entry_id)
await hass.async_block_till_done()

result = await old_entry.start_reauth_flow(hass)

Expand All @@ -200,10 +198,7 @@ async def test_reauth_account_mismatch(
},
)

with patch(
"homeassistant.components.teslemetry.async_setup_entry", return_value=True
):
result = await hass.config_entries.flow.async_configure(result["flow_id"])
result = await hass.config_entries.flow.async_configure(result["flow_id"])

assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_account_mismatch"
Expand Down Expand Up @@ -349,6 +344,7 @@ async def test_reconfigure(


@pytest.mark.usefixtures("current_request_with_host")
@pytest.mark.usefixtures("mock_setup_entry")
async def test_reconfigure_account_mismatch(
hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator,
Expand All @@ -373,11 +369,8 @@ async def test_reconfigure_account_mismatch(
old_entry.add_to_hass(hass)

# Setup the integration properly to import client credentials
with patch(
"homeassistant.components.teslemetry.async_setup_entry", return_value=True
):
await hass.config_entries.async_setup(old_entry.entry_id)
await hass.async_block_till_done()
await hass.config_entries.async_setup(old_entry.entry_id)
await hass.async_block_till_done()

client = await hass_client_no_auth()
result = await old_entry.start_reconfigure_flow(hass)
Expand All @@ -392,10 +385,7 @@ async def test_reconfigure_account_mismatch(
await client.get(f"/auth/external/callback?code=abcd&state={state}")
aioclient_mock.post(TOKEN_URL, json=mock_token_response)

with patch(
"homeassistant.components.teslemetry.async_setup_entry", return_value=True
):
result = await hass.config_entries.flow.async_configure(result["flow_id"])
result = await hass.config_entries.flow.async_configure(result["flow_id"])

assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfigure_account_mismatch"
Expand Down
Loading