Remove deprecated zamg YAML config (#86113)

This commit is contained in:
Daniel Gangl 2023-01-17 21:58:20 +01:00 committed by GitHub
parent 1c2510bfb3
commit cc74fcbda7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 268 deletions

View file

@ -1,15 +1,14 @@
"""Tests for the Zamg config flow."""
from unittest.mock import MagicMock
from zamg.exceptions import ZamgApiError, ZamgStationNotFoundError
from zamg.exceptions import ZamgApiError
from homeassistant.components.zamg.const import CONF_STATION_ID, DOMAIN, LOGGER
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.const import CONF_NAME
from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from .conftest import TEST_STATION_ID, TEST_STATION_NAME
from .conftest import TEST_STATION_ID
async def test_full_user_flow_implementation(
@ -75,21 +74,6 @@ async def test_error_update(
assert result.get("reason") == "cannot_connect"
async def test_full_import_flow_implementation(
hass: HomeAssistant,
mock_zamg: MagicMock,
mock_setup_entry: None,
) -> None:
"""Test the full import flow from start to finish."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_STATION_ID: TEST_STATION_ID, CONF_NAME: TEST_STATION_NAME},
)
assert result.get("type") == FlowResultType.CREATE_ENTRY
assert result.get("data") == {CONF_STATION_ID: TEST_STATION_ID}
async def test_user_flow_duplicate(
hass: HomeAssistant,
mock_zamg: MagicMock,
@ -125,114 +109,3 @@ async def test_user_flow_duplicate(
)
assert result.get("type") == FlowResultType.ABORT
assert result.get("reason") == "already_configured"
async def test_import_flow_duplicate(
hass: HomeAssistant,
mock_zamg: MagicMock,
mock_setup_entry: None,
) -> None:
"""Test import flow with duplicate entry."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
)
assert result.get("step_id") == "user"
assert result.get("type") == FlowResultType.FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={CONF_STATION_ID: TEST_STATION_ID},
)
assert result.get("type") == FlowResultType.CREATE_ENTRY
assert "data" in result
assert result["data"][CONF_STATION_ID] == TEST_STATION_ID
assert "result" in result
assert result["result"].unique_id == TEST_STATION_ID
# try to add another instance
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_STATION_ID: TEST_STATION_ID, CONF_NAME: TEST_STATION_NAME},
)
assert result.get("type") == FlowResultType.ABORT
assert result.get("reason") == "already_configured"
async def test_import_flow_duplicate_after_position(
hass: HomeAssistant,
mock_zamg: MagicMock,
mock_setup_entry: None,
) -> None:
"""Test import flow with duplicate entry."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
)
assert result.get("step_id") == "user"
assert result.get("type") == FlowResultType.FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={CONF_STATION_ID: TEST_STATION_ID},
)
assert result.get("type") == FlowResultType.CREATE_ENTRY
assert "data" in result
assert result["data"][CONF_STATION_ID] == TEST_STATION_ID
assert "result" in result
assert result["result"].unique_id == TEST_STATION_ID
# try to add another instance
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_STATION_ID: "123", CONF_NAME: TEST_STATION_NAME},
)
assert result.get("type") == FlowResultType.ABORT
assert result.get("reason") == "already_configured"
async def test_import_flow_no_name(
hass: HomeAssistant,
mock_zamg: MagicMock,
mock_setup_entry: None,
) -> None:
"""Test import flow without any name."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_STATION_ID: TEST_STATION_ID},
)
assert result.get("type") == FlowResultType.CREATE_ENTRY
assert result.get("data") == {CONF_STATION_ID: TEST_STATION_ID}
async def test_import_flow_invalid_station(
hass: HomeAssistant,
mock_zamg: MagicMock,
mock_setup_entry: None,
) -> None:
"""Test import flow with invalid station."""
mock_zamg.closest_station.side_effect = ZamgStationNotFoundError
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_STATION_ID: ""},
)
assert result.get("type") == FlowResultType.ABORT
assert result.get("reason") == "station_not_found"
async def test_import_flow_zamg_error(
hass: HomeAssistant,
mock_zamg: MagicMock,
mock_setup_entry: None,
) -> None:
"""Test import flow with error on getting zamg stations."""
mock_zamg.zamg_stations.side_effect = ZamgApiError
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_STATION_ID: ""},
)
assert result.get("type") == FlowResultType.ABORT
assert result.get("reason") == "cannot_connect"