Increase test coverage in Habitica integration (#135896)

Add tests to Habitica integration
This commit is contained in:
Manu 2025-01-18 12:59:23 +01:00 committed by GitHub
parent 88f16807a0
commit f5dd3ef530
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 63 additions and 3 deletions

View File

@ -4,9 +4,7 @@ rules:
appropriate-polling: done
brands: done
common-modules: done
config-flow-test-coverage:
status: todo
comment: test already_configured, tests should finish with create_entry or abort, assert unique_id
config-flow-test-coverage: done
config-flow: done
dependency-transparency: todo
docs-actions: done

View File

@ -147,6 +147,35 @@ async def test_form_login_errors(
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")
async def test_form_advanced(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
"""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 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