mirror of
https://github.com/home-assistant/core.git
synced 2025-04-19 14:57:52 +00:00
Cleanup lamarzocco tests (#143176)
This commit is contained in:
parent
8355727eb1
commit
b88bf74e13
@ -1,7 +1,7 @@
|
||||
"""Lamarzocco session fixtures."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from bleak.backends.device import BLEDevice
|
||||
from pylamarzocco.const import ModelName
|
||||
@ -22,15 +22,6 @@ from . import SERIAL_DICT, USER_INPUT, async_init_integration
|
||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock]:
|
||||
"""Override async_setup_entry."""
|
||||
with patch(
|
||||
"homeassistant.components.lamarzocco.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
yield mock_setup_entry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_entry(
|
||||
hass: HomeAssistant, mock_lamarzocco: MagicMock
|
||||
|
@ -18,7 +18,6 @@ from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_plat
|
||||
|
||||
async def test_binary_sensors(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
|
@ -27,6 +27,15 @@ from . import USER_INPUT, async_init_integration, get_bluetooth_service_info
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_setup_entry() -> Generator[AsyncMock]:
|
||||
"""Override async_setup_entry."""
|
||||
with patch(
|
||||
"homeassistant.components.lamarzocco.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
yield mock_setup_entry
|
||||
|
||||
|
||||
async def __do_successful_user_step(
|
||||
hass: HomeAssistant, result: ConfigFlowResult, mock_cloud_client: MagicMock
|
||||
) -> ConfigFlowResult:
|
||||
@ -47,25 +56,24 @@ async def __do_sucessful_machine_selection_step(
|
||||
) -> None:
|
||||
"""Successfully configure the machine selection step."""
|
||||
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
{CONF_MACHINE: "GS012345"},
|
||||
)
|
||||
|
||||
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
assert result3["title"] == "GS012345"
|
||||
assert result3["data"] == {
|
||||
assert result["title"] == "GS012345"
|
||||
assert result["data"] == {
|
||||
**USER_INPUT,
|
||||
CONF_TOKEN: None,
|
||||
}
|
||||
assert result3["result"].unique_id == "GS012345"
|
||||
assert result["result"].unique_id == "GS012345"
|
||||
|
||||
|
||||
async def test_form(
|
||||
hass: HomeAssistant,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_setup_entry: Generator[AsyncMock],
|
||||
) -> None:
|
||||
"""Test we get the form."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@ -75,13 +83,12 @@ async def test_form(
|
||||
assert result["errors"] == {}
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await __do_successful_user_step(hass, result, mock_cloud_client)
|
||||
await __do_sucessful_machine_selection_step(hass, result2)
|
||||
result = await __do_successful_user_step(hass, result, mock_cloud_client)
|
||||
await __do_sucessful_machine_selection_step(hass, result)
|
||||
|
||||
|
||||
async def test_form_abort_already_configured(
|
||||
hass: HomeAssistant,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test we abort if already configured."""
|
||||
@ -93,25 +100,25 @@ async def test_form_abort_already_configured(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {}
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["step_id"] == "machine_selection"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "machine_selection"
|
||||
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_MACHINE: "GS012345",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] is FlowResultType.ABORT
|
||||
assert result3["reason"] == "already_configured"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -124,7 +131,6 @@ async def test_form_abort_already_configured(
|
||||
async def test_form_invalid_auth(
|
||||
hass: HomeAssistant,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_setup_entry: Generator[AsyncMock],
|
||||
side_effect: Exception,
|
||||
error: str,
|
||||
) -> None:
|
||||
@ -135,25 +141,24 @@ async def test_form_invalid_auth(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": error}
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": error}
|
||||
assert len(mock_cloud_client.list_things.mock_calls) == 1
|
||||
|
||||
# test recovery from failure
|
||||
mock_cloud_client.list_things.side_effect = None
|
||||
result2 = await __do_successful_user_step(hass, result, mock_cloud_client)
|
||||
await __do_sucessful_machine_selection_step(hass, result2)
|
||||
result = await __do_successful_user_step(hass, result, mock_cloud_client)
|
||||
await __do_sucessful_machine_selection_step(hass, result)
|
||||
|
||||
|
||||
async def test_form_no_machines(
|
||||
hass: HomeAssistant,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_setup_entry: Generator[AsyncMock],
|
||||
) -> None:
|
||||
"""Test we don't have any devices."""
|
||||
|
||||
@ -164,20 +169,20 @@ async def test_form_no_machines(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": "no_machines"}
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "no_machines"}
|
||||
assert len(mock_cloud_client.list_things.mock_calls) == 1
|
||||
|
||||
# test recovery from failure
|
||||
mock_cloud_client.list_things.return_value = original_return
|
||||
|
||||
result2 = await __do_successful_user_step(hass, result, mock_cloud_client)
|
||||
await __do_sucessful_machine_selection_step(hass, result2)
|
||||
result = await __do_successful_user_step(hass, result, mock_cloud_client)
|
||||
await __do_sucessful_machine_selection_step(hass, result)
|
||||
|
||||
|
||||
async def test_reauth_flow(
|
||||
@ -194,14 +199,14 @@ async def test_reauth_flow(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_PASSWORD: "new_password"},
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.ABORT
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
await hass.async_block_till_done()
|
||||
assert result2["reason"] == "reauth_successful"
|
||||
assert result["reason"] == "reauth_successful"
|
||||
assert len(mock_cloud_client.list_things.mock_calls) == 1
|
||||
assert mock_config_entry.data[CONF_PASSWORD] == "new_password"
|
||||
|
||||
@ -210,7 +215,6 @@ async def test_reconfigure_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_setup_entry: Generator[AsyncMock],
|
||||
) -> None:
|
||||
"""Testing reconfgure flow."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
@ -220,7 +224,7 @@ async def test_reconfigure_flow(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reconfigure"
|
||||
|
||||
result2 = await __do_successful_user_step(hass, result, mock_cloud_client)
|
||||
result = await __do_successful_user_step(hass, result, mock_cloud_client)
|
||||
service_info = get_bluetooth_service_info(ModelName.GS3_MP, "GS012345")
|
||||
|
||||
with (
|
||||
@ -229,24 +233,24 @@ async def test_reconfigure_flow(
|
||||
return_value=[service_info],
|
||||
),
|
||||
):
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_MACHINE: "GS012345",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] is FlowResultType.FORM
|
||||
assert result3["step_id"] == "bluetooth_selection"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "bluetooth_selection"
|
||||
|
||||
result4 = await hass.config_entries.flow.async_configure(
|
||||
result3["flow_id"],
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_MAC: service_info.address},
|
||||
)
|
||||
|
||||
assert result4["type"] is FlowResultType.ABORT
|
||||
assert result4["reason"] == "reconfigure_successful"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
|
||||
assert mock_config_entry.title == "My LaMarzocco"
|
||||
assert mock_config_entry.data == {
|
||||
@ -259,7 +263,6 @@ async def test_bluetooth_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_setup_entry: Generator[AsyncMock],
|
||||
) -> None:
|
||||
"""Test bluetooth discovery."""
|
||||
service_info = get_bluetooth_service_info(
|
||||
@ -274,14 +277,14 @@ async def test_bluetooth_discovery(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
)
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
assert result2["title"] == "GS012345"
|
||||
assert result2["data"] == {
|
||||
assert result["title"] == "GS012345"
|
||||
assert result["data"] == {
|
||||
**USER_INPUT,
|
||||
CONF_MAC: "aa:bb:cc:dd:ee:ff",
|
||||
CONF_TOKEN: "dummyToken",
|
||||
@ -291,8 +294,6 @@ async def test_bluetooth_discovery(
|
||||
async def test_bluetooth_discovery_already_configured(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_setup_entry: Generator[AsyncMock],
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test bluetooth discovery."""
|
||||
@ -312,7 +313,6 @@ async def test_bluetooth_discovery_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_setup_entry: Generator[AsyncMock],
|
||||
) -> None:
|
||||
"""Test bluetooth discovery errors."""
|
||||
service_info = get_bluetooth_service_info(
|
||||
@ -330,24 +330,24 @@ async def test_bluetooth_discovery_errors(
|
||||
original_return = deepcopy(mock_cloud_client.list_things.return_value)
|
||||
mock_cloud_client.list_things.return_value[0].serial_number = "GS98765"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
)
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": "machine_not_found"}
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "machine_not_found"}
|
||||
assert len(mock_cloud_client.list_things.mock_calls) == 1
|
||||
|
||||
mock_cloud_client.list_things.return_value = original_return
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
assert result2["title"] == "GS012345"
|
||||
assert result2["data"] == {
|
||||
assert result["title"] == "GS012345"
|
||||
assert result["data"] == {
|
||||
**USER_INPUT,
|
||||
CONF_MAC: "aa:bb:cc:dd:ee:ff",
|
||||
CONF_TOKEN: None,
|
||||
@ -357,8 +357,6 @@ async def test_bluetooth_discovery_errors(
|
||||
async def test_dhcp_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_setup_entry: Generator[AsyncMock],
|
||||
) -> None:
|
||||
"""Test dhcp discovery."""
|
||||
|
||||
@ -375,12 +373,12 @@ async def test_dhcp_discovery(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
)
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result2["data"] == {
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"] == {
|
||||
**USER_INPUT,
|
||||
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
||||
CONF_TOKEN: None,
|
||||
@ -389,8 +387,6 @@ async def test_dhcp_discovery(
|
||||
|
||||
async def test_dhcp_discovery_abort_on_hostname_changed(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test dhcp discovery aborts when hostname was changed manually."""
|
||||
@ -411,7 +407,6 @@ async def test_dhcp_discovery_abort_on_hostname_changed(
|
||||
async def test_dhcp_already_configured_and_update(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test discovered IP address change."""
|
||||
@ -436,9 +431,7 @@ async def test_dhcp_already_configured_and_update(
|
||||
|
||||
async def test_options_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_setup_entry: Generator[AsyncMock],
|
||||
) -> None:
|
||||
"""Test options flow."""
|
||||
await async_init_integration(hass, mock_config_entry)
|
||||
@ -449,7 +442,7 @@ async def test_options_flow(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result2 = await hass.config_entries.options.async_configure(
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_USE_BLUETOOTH: False,
|
||||
@ -457,7 +450,7 @@ async def test_options_flow(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result2["data"] == {
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"] == {
|
||||
CONF_USE_BLUETOOTH: False,
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ from tests.common import MockConfigEntry
|
||||
async def test_load_unload_config_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_lamarzocco: MagicMock,
|
||||
) -> None:
|
||||
"""Test loading and unloading the integration."""
|
||||
await async_init_integration(hass, mock_config_entry)
|
||||
@ -111,7 +110,6 @@ async def test_invalid_auth(
|
||||
|
||||
async def test_v1_migration_fails(
|
||||
hass: HomeAssistant,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_lamarzocco: MagicMock,
|
||||
) -> None:
|
||||
"""Test v1 -> v2 Migration."""
|
||||
@ -131,7 +129,6 @@ async def test_v1_migration_fails(
|
||||
|
||||
async def test_v2_migration(
|
||||
hass: HomeAssistant,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_lamarzocco: MagicMock,
|
||||
) -> None:
|
||||
"""Test v2 -> v3 Migration."""
|
||||
@ -256,7 +253,6 @@ async def test_websocket_closed_on_unload(
|
||||
async def test_gateway_version_issue(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_cloud_client: MagicMock,
|
||||
version: str,
|
||||
issue_exists: bool,
|
||||
|
@ -25,7 +25,6 @@ from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
async def test_switches(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
|
@ -19,7 +19,6 @@ from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
async def test_update(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
|
Loading…
x
Reference in New Issue
Block a user