mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Increase test coverage in Habitica integration (#135896)
Add tests to Habitica integration
This commit is contained in:
parent
88f16807a0
commit
f5dd3ef530
@ -4,9 +4,7 @@ rules:
|
|||||||
appropriate-polling: done
|
appropriate-polling: done
|
||||||
brands: done
|
brands: done
|
||||||
common-modules: done
|
common-modules: done
|
||||||
config-flow-test-coverage:
|
config-flow-test-coverage: done
|
||||||
status: todo
|
|
||||||
comment: test already_configured, tests should finish with create_entry or abort, assert unique_id
|
|
||||||
config-flow: done
|
config-flow: done
|
||||||
dependency-transparency: todo
|
dependency-transparency: todo
|
||||||
docs-actions: done
|
docs-actions: done
|
||||||
|
@ -147,6 +147,35 @@ async def test_form_login_errors(
|
|||||||
assert result["result"].unique_id == TEST_API_USER
|
assert result["result"].unique_id == TEST_API_USER
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("habitica")
|
||||||
|
async def test_form__already_configured(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test we abort form login when entry is already configured."""
|
||||||
|
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.MENU
|
||||||
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": "advanced"}
|
||||||
|
)
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input=MOCK_DATA_ADVANCED_STEP,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("habitica")
|
@pytest.mark.usefixtures("habitica")
|
||||||
async def test_form_advanced(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
async def test_form_advanced(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
@ -387,3 +416,36 @@ async def test_flow_reauth_errors(
|
|||||||
assert config_entry.data[CONF_API_KEY] == "cd0e5985-17de-4b4f-849e-5d506c5e4382"
|
assert config_entry.data[CONF_API_KEY] == "cd0e5985-17de-4b4f-849e-5d506c5e4382"
|
||||||
|
|
||||||
assert len(hass.config_entries.async_entries()) == 1
|
assert len(hass.config_entries.async_entries()) == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("habitica")
|
||||||
|
async def test_flow_reauth_unique_id_mismatch(hass: HomeAssistant) -> None:
|
||||||
|
"""Test reauth flow."""
|
||||||
|
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
title="test-user",
|
||||||
|
data={
|
||||||
|
CONF_URL: DEFAULT_URL,
|
||||||
|
CONF_API_USER: "371fcad5-0f9c-4211-931c-034a5d2a6213",
|
||||||
|
CONF_API_KEY: "cd0e5985-17de-4b4f-849e-5d506c5e4382",
|
||||||
|
},
|
||||||
|
unique_id="371fcad5-0f9c-4211-931c-034a5d2a6213",
|
||||||
|
)
|
||||||
|
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
result = await config_entry.start_reauth_flow(hass)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "reauth_confirm"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
USER_INPUT_REAUTH_LOGIN,
|
||||||
|
)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "unique_id_mismatch"
|
||||||
|
|
||||||
|
assert len(hass.config_entries.async_entries()) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user