2019-02-08 09:55:58 +00:00
|
|
|
"""Tests for IPMA config flow."""
|
2023-08-16 10:56:47 +00:00
|
|
|
from unittest.mock import patch
|
2021-01-01 21:31:56 +00:00
|
|
|
|
2023-08-16 10:56:47 +00:00
|
|
|
import pytest
|
2019-02-08 09:55:58 +00:00
|
|
|
|
2023-08-16 10:56:47 +00:00
|
|
|
from homeassistant import config_entries, data_entry_flow
|
|
|
|
from homeassistant.components.ipma.const import DOMAIN
|
|
|
|
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
|
|
|
from homeassistant.core import HomeAssistant
|
2019-02-08 09:55:58 +00:00
|
|
|
|
|
|
|
|
2023-08-16 10:56:47 +00:00
|
|
|
@pytest.fixture(name="ipma_setup", autouse=True)
|
|
|
|
def ipma_setup_fixture(request):
|
|
|
|
"""Patch ipma setup entry."""
|
|
|
|
with patch("homeassistant.components.ipma.async_setup_entry", return_value=True):
|
|
|
|
yield
|
2019-02-08 09:55:58 +00:00
|
|
|
|
|
|
|
|
2023-08-16 10:56:47 +00:00
|
|
|
async def test_config_flow(hass: HomeAssistant) -> None:
|
|
|
|
"""Test configuration form."""
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
|
|
)
|
2019-02-08 09:55:58 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert result["type"] == "form"
|
|
|
|
assert result["step_id"] == "user"
|
2019-02-08 09:55:58 +00:00
|
|
|
|
2023-08-16 10:56:47 +00:00
|
|
|
test_data = {
|
|
|
|
CONF_LONGITUDE: 0,
|
|
|
|
CONF_LATITUDE: 0,
|
|
|
|
}
|
2019-02-08 09:55:58 +00:00
|
|
|
|
2023-08-16 10:56:47 +00:00
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
|
|
|
test_data,
|
|
|
|
)
|
2019-02-08 09:55:58 +00:00
|
|
|
|
2023-08-16 10:56:47 +00:00
|
|
|
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
|
|
|
|
assert result["title"] == "Home"
|
|
|
|
assert result["data"] == {
|
|
|
|
CONF_NAME: "Home",
|
|
|
|
CONF_LONGITUDE: 0,
|
|
|
|
CONF_LATITUDE: 0,
|
|
|
|
}
|
2019-02-08 09:55:58 +00:00
|
|
|
|
|
|
|
|
2023-08-16 10:56:47 +00:00
|
|
|
async def test_flow_entry_already_exists(hass: HomeAssistant, config_entry) -> None:
|
|
|
|
"""Test user input for config_entry that already exists.
|
2019-02-08 09:55:58 +00:00
|
|
|
|
2023-08-16 10:56:47 +00:00
|
|
|
Test when the form should show when user puts existing location
|
|
|
|
in the config gui. Then the form should show with error.
|
2019-02-08 09:55:58 +00:00
|
|
|
"""
|
2023-08-16 10:56:47 +00:00
|
|
|
test_data = {
|
|
|
|
CONF_NAME: "Home",
|
|
|
|
CONF_LONGITUDE: 0,
|
|
|
|
CONF_LATITUDE: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert result["type"] == "abort"
|
|
|
|
assert result["reason"] == "already_configured"
|