Cleanup use of test fixtures in LaMetric tests (#88453)
Cleanup use of test fixture in LaMetric tests
This commit is contained in:
parent
172d505314
commit
c4f92f5ad4
9 changed files with 115 additions and 160 deletions
|
@ -54,22 +54,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_lametric_config_flow() -> Generator[MagicMock, None, None]:
|
||||
"""Return a mocked LaMetric client."""
|
||||
with patch(
|
||||
"homeassistant.components.lametric.config_flow.LaMetricDevice", autospec=True
|
||||
) as lametric_mock:
|
||||
lametric = lametric_mock.return_value
|
||||
lametric.api_key = "mock-api-key"
|
||||
lametric.host = "127.0.0.1"
|
||||
lametric.device.return_value = Device.parse_raw(
|
||||
load_fixture("device.json", DOMAIN)
|
||||
)
|
||||
yield lametric
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_lametric_cloud_config_flow() -> Generator[MagicMock, None, None]:
|
||||
def mock_lametric_cloud() -> Generator[MagicMock, None, None]:
|
||||
"""Return a mocked LaMetric Cloud client."""
|
||||
with patch(
|
||||
"homeassistant.components.lametric.config_flow.LaMetricCloud", autospec=True
|
||||
|
@ -86,7 +71,10 @@ def mock_lametric() -> Generator[MagicMock, None, None]:
|
|||
"""Return a mocked LaMetric client."""
|
||||
with patch(
|
||||
"homeassistant.components.lametric.coordinator.LaMetricDevice", autospec=True
|
||||
) as lametric_mock:
|
||||
) as lametric_mock, patch(
|
||||
"homeassistant.components.lametric.config_flow.LaMetricDevice",
|
||||
new=lametric_mock,
|
||||
):
|
||||
lametric = lametric_mock.return_value
|
||||
lametric.api_key = "mock-api-key"
|
||||
lametric.host = "127.0.0.1"
|
||||
|
|
|
@ -17,19 +17,19 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
pytestmark = [
|
||||
pytest.mark.usefixtures("init_integration"),
|
||||
pytest.mark.freeze_time("2022-09-19 12:07:30"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2022-09-19 12:07:30")
|
||||
async def test_button_app_next(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the LaMetric next app button."""
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("button.frenck_s_lametric_next_app")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:arrow-right-bold"
|
||||
|
@ -70,16 +70,13 @@ async def test_button_app_next(
|
|||
assert state.state == "2022-09-19T12:07:30+00:00"
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2022-09-19 12:07:30")
|
||||
async def test_button_app_previous(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the LaMetric previous app button."""
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("button.frenck_s_lametric_previous_app")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:arrow-left-bold"
|
||||
|
@ -120,16 +117,13 @@ async def test_button_app_previous(
|
|||
assert state.state == "2022-09-19T12:07:30+00:00"
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2022-10-19 12:44:00")
|
||||
async def test_button_dismiss_current_notification(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the LaMetric dismiss current notification button."""
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("button.frenck_s_lametric_dismiss_current_notification")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:bell-cancel"
|
||||
|
@ -169,19 +163,16 @@ async def test_button_dismiss_current_notification(
|
|||
|
||||
state = hass.states.get("button.frenck_s_lametric_dismiss_current_notification")
|
||||
assert state
|
||||
assert state.state == "2022-10-19T12:44:00+00:00"
|
||||
assert state.state == "2022-09-19T12:07:30+00:00"
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2022-10-19 12:44:00")
|
||||
async def test_button_dismiss_all_notifications(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the LaMetric dismiss all notifications button."""
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("button.frenck_s_lametric_dismiss_all_notifications")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:bell-cancel"
|
||||
|
@ -221,13 +212,11 @@ async def test_button_dismiss_all_notifications(
|
|||
|
||||
state = hass.states.get("button.frenck_s_lametric_dismiss_all_notifications")
|
||||
assert state
|
||||
assert state.state == "2022-10-19T12:44:00+00:00"
|
||||
assert state.state == "2022-09-19T12:07:30+00:00"
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2022-10-11 22:00:00")
|
||||
async def test_button_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test error handling of the LaMetric buttons."""
|
||||
|
@ -246,12 +235,11 @@ async def test_button_error(
|
|||
|
||||
state = hass.states.get("button.frenck_s_lametric_next_app")
|
||||
assert state
|
||||
assert state.state == "2022-10-11T22:00:00+00:00"
|
||||
assert state.state == "2022-09-19T12:07:30+00:00"
|
||||
|
||||
|
||||
async def test_button_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test connection error handling of the LaMetric buttons."""
|
||||
|
|
|
@ -42,14 +42,14 @@ SSDP_DISCOVERY_INFO = SsdpServiceInfo(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("current_request_with_host")
|
||||
async def test_full_cloud_import_flow_multiple_devices(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
current_request_with_host: None,
|
||||
mock_setup_entry: MagicMock,
|
||||
mock_lametric_cloud_config_flow: MagicMock,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric_cloud: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Check a full flow importing from cloud, with multiple devices."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -116,20 +116,20 @@ async def test_full_cloud_import_flow_multiple_devices(
|
|||
assert "result" in result4
|
||||
assert result4["result"].unique_id == "SA110405124500W00BS9"
|
||||
|
||||
assert len(mock_lametric_cloud_config_flow.devices.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 1
|
||||
assert len(mock_lametric_cloud.devices.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("current_request_with_host")
|
||||
async def test_full_cloud_import_flow_single_device(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
current_request_with_host: None,
|
||||
mock_setup_entry: MagicMock,
|
||||
mock_lametric_cloud_config_flow: MagicMock,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric_cloud: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Check a full flow importing from cloud, with a single device."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -179,8 +179,8 @@ async def test_full_cloud_import_flow_single_device(
|
|||
|
||||
# Stage a single device
|
||||
# Should skip step that ask for device selection
|
||||
mock_lametric_cloud_config_flow.devices.return_value = [
|
||||
mock_lametric_cloud_config_flow.devices.return_value[0]
|
||||
mock_lametric_cloud.devices.return_value = [
|
||||
mock_lametric_cloud.devices.return_value[0]
|
||||
]
|
||||
result3 = await hass.config_entries.flow.async_configure(flow_id)
|
||||
|
||||
|
@ -194,16 +194,16 @@ async def test_full_cloud_import_flow_single_device(
|
|||
assert "result" in result3
|
||||
assert result3["result"].unique_id == "SA110405124500W00BS9"
|
||||
|
||||
assert len(mock_lametric_cloud_config_flow.devices.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 1
|
||||
assert len(mock_lametric_cloud.devices.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_full_manual(
|
||||
hass: HomeAssistant,
|
||||
mock_setup_entry: MagicMock,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Check a full flow manual entry."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -236,19 +236,19 @@ async def test_full_manual(
|
|||
assert "result" in result3
|
||||
assert result3["result"].unique_id == "SA110405124500W00BS9"
|
||||
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("current_request_with_host")
|
||||
async def test_full_ssdp_with_cloud_import(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
current_request_with_host: None,
|
||||
mock_setup_entry: MagicMock,
|
||||
mock_lametric_cloud_config_flow: MagicMock,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric_cloud: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Check a full flow triggered by SSDP, importing from cloud."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -308,16 +308,16 @@ async def test_full_ssdp_with_cloud_import(
|
|||
assert "result" in result3
|
||||
assert result3["result"].unique_id == "SA110405124500W00BS9"
|
||||
|
||||
assert len(mock_lametric_cloud_config_flow.devices.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 1
|
||||
assert len(mock_lametric_cloud.devices.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_full_ssdp_manual_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_setup_entry: MagicMock,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Check a full flow triggered by SSDP, with manual API key entry."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -350,8 +350,8 @@ async def test_full_ssdp_manual_entry(
|
|||
assert "result" in result3
|
||||
assert result3["result"].unique_id == "SA110405124500W00BS9"
|
||||
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
|
@ -386,13 +386,13 @@ async def test_ssdp_abort_invalid_discovery(
|
|||
assert result.get("reason") == reason
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("current_request_with_host")
|
||||
async def test_cloud_import_updates_existing_entry(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
current_request_with_host: None,
|
||||
mock_lametric_cloud_config_flow: MagicMock,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric_cloud: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test cloud importing existing device updates existing entry."""
|
||||
|
@ -439,14 +439,14 @@ async def test_cloud_import_updates_existing_entry(
|
|||
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
||||
}
|
||||
|
||||
assert len(mock_lametric_cloud_config_flow.devices.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 0
|
||||
assert len(mock_lametric_cloud.devices.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_manual_updates_existing_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test adding existing device updates existing entry."""
|
||||
|
@ -473,8 +473,8 @@ async def test_manual_updates_existing_entry(
|
|||
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
||||
}
|
||||
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 0
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_discovery_updates_existing_entry(
|
||||
|
@ -496,12 +496,12 @@ async def test_discovery_updates_existing_entry(
|
|||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("current_request_with_host")
|
||||
async def test_cloud_abort_no_devices(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
current_request_with_host: None,
|
||||
mock_lametric_cloud_config_flow: MagicMock,
|
||||
mock_lametric_cloud: MagicMock,
|
||||
) -> None:
|
||||
"""Test cloud importing aborts when account has no devices."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -533,13 +533,13 @@ async def test_cloud_abort_no_devices(
|
|||
)
|
||||
|
||||
# Stage there are no devices
|
||||
mock_lametric_cloud_config_flow.devices.return_value = []
|
||||
mock_lametric_cloud.devices.return_value = []
|
||||
result2 = await hass.config_entries.flow.async_configure(flow_id)
|
||||
|
||||
assert result2.get("type") == FlowResultType.ABORT
|
||||
assert result2.get("reason") == "no_devices"
|
||||
|
||||
assert len(mock_lametric_cloud_config_flow.devices.mock_calls) == 1
|
||||
assert len(mock_lametric_cloud.devices.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -553,7 +553,7 @@ async def test_cloud_abort_no_devices(
|
|||
)
|
||||
async def test_manual_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
mock_setup_entry: MagicMock,
|
||||
side_effect: Exception,
|
||||
reason: str,
|
||||
|
@ -568,7 +568,7 @@ async def test_manual_errors(
|
|||
flow_id, user_input={"next_step_id": "manual_entry"}
|
||||
)
|
||||
|
||||
mock_lametric_config_flow.device.side_effect = side_effect
|
||||
mock_lametric.device.side_effect = side_effect
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
flow_id, user_input={CONF_HOST: "127.0.0.1", CONF_API_KEY: "mock-api-key"}
|
||||
)
|
||||
|
@ -577,11 +577,11 @@ async def test_manual_errors(
|
|||
assert result2.get("step_id") == "manual_entry"
|
||||
assert result2.get("errors") == {"base": reason}
|
||||
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 0
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
|
||||
mock_lametric_config_flow.device.side_effect = None
|
||||
mock_lametric.device.side_effect = None
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
flow_id, user_input={CONF_HOST: "127.0.0.1", CONF_API_KEY: "mock-api-key"}
|
||||
)
|
||||
|
@ -596,11 +596,12 @@ async def test_manual_errors(
|
|||
assert "result" in result3
|
||||
assert result3["result"].unique_id == "SA110405124500W00BS9"
|
||||
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 2
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 2
|
||||
assert len(mock_lametric.notify.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("current_request_with_host")
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "reason"),
|
||||
[
|
||||
|
@ -614,10 +615,9 @@ async def test_cloud_errors(
|
|||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
current_request_with_host: None,
|
||||
mock_setup_entry: MagicMock,
|
||||
mock_lametric_cloud_config_flow: MagicMock,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric_cloud: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
side_effect: Exception,
|
||||
reason: str,
|
||||
) -> None:
|
||||
|
@ -651,7 +651,7 @@ async def test_cloud_errors(
|
|||
)
|
||||
await hass.config_entries.flow.async_configure(flow_id)
|
||||
|
||||
mock_lametric_config_flow.device.side_effect = side_effect
|
||||
mock_lametric.device.side_effect = side_effect
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
flow_id, user_input={CONF_DEVICE: "SA110405124500W00BS9"}
|
||||
)
|
||||
|
@ -660,12 +660,12 @@ async def test_cloud_errors(
|
|||
assert result2.get("step_id") == "cloud_select_device"
|
||||
assert result2.get("errors") == {"base": reason}
|
||||
|
||||
assert len(mock_lametric_cloud_config_flow.devices.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 0
|
||||
assert len(mock_lametric_cloud.devices.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
|
||||
mock_lametric_config_flow.device.side_effect = None
|
||||
mock_lametric.device.side_effect = None
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
flow_id, user_input={CONF_DEVICE: "SA110405124500W00BS9"}
|
||||
)
|
||||
|
@ -680,9 +680,9 @@ async def test_cloud_errors(
|
|||
assert "result" in result3
|
||||
assert result3["result"].unique_id == "SA110405124500W00BS9"
|
||||
|
||||
assert len(mock_lametric_cloud_config_flow.devices.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 2
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 1
|
||||
assert len(mock_lametric_cloud.devices.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 2
|
||||
assert len(mock_lametric.notify.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
|
@ -733,14 +733,13 @@ async def test_dhcp_unknown_device(
|
|||
assert result.get("reason") == "unknown"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("current_request_with_host", "mock_setup_entry")
|
||||
async def test_reauth_cloud_import(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
current_request_with_host: None,
|
||||
mock_setup_entry: MagicMock,
|
||||
mock_lametric_cloud_config_flow: MagicMock,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric_cloud: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test reauth flow importing api keys from the cloud."""
|
||||
|
@ -792,19 +791,18 @@ async def test_reauth_cloud_import(
|
|||
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
||||
}
|
||||
|
||||
assert len(mock_lametric_cloud_config_flow.devices.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 1
|
||||
assert len(mock_lametric_cloud.devices.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("current_request_with_host", "mock_setup_entry")
|
||||
async def test_reauth_cloud_abort_device_not_found(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
current_request_with_host: None,
|
||||
mock_setup_entry: MagicMock,
|
||||
mock_lametric_cloud_config_flow: MagicMock,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric_cloud: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test reauth flow importing api keys from the cloud."""
|
||||
|
@ -852,15 +850,15 @@ async def test_reauth_cloud_abort_device_not_found(
|
|||
assert result2.get("type") == FlowResultType.ABORT
|
||||
assert result2.get("reason") == "reauth_device_not_found"
|
||||
|
||||
assert len(mock_lametric_cloud_config_flow.devices.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 0
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 0
|
||||
assert len(mock_lametric_cloud.devices.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 0
|
||||
assert len(mock_lametric.notify.mock_calls) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_reauth_manual(
|
||||
hass: HomeAssistant,
|
||||
mock_setup_entry: MagicMock,
|
||||
mock_lametric_config_flow: MagicMock,
|
||||
mock_lametric: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test reauth flow with manual entry."""
|
||||
|
@ -894,5 +892,5 @@ async def test_reauth_manual(
|
|||
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
||||
}
|
||||
|
||||
assert len(mock_lametric_config_flow.device.mock_calls) == 1
|
||||
assert len(mock_lametric_config_flow.notify.mock_calls) == 1
|
||||
assert len(mock_lametric.device.mock_calls) == 1
|
||||
assert len(mock_lametric.notify.mock_calls) == 1
|
||||
|
|
|
@ -20,14 +20,13 @@ from homeassistant.components.notify import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
NOTIFY_SERVICE = "frenck_s_lametric"
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
async def test_notification_defaults(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test the LaMetric notification defaults."""
|
||||
|
@ -64,7 +63,6 @@ async def test_notification_defaults(
|
|||
|
||||
async def test_notification_options(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test the LaMetric notification options."""
|
||||
|
@ -107,7 +105,6 @@ async def test_notification_options(
|
|||
|
||||
async def test_notification_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test the LaMetric notification error."""
|
||||
|
|
|
@ -27,18 +27,16 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
async def test_brightness(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the LaMetric display brightness controls."""
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("number.frenck_s_lametric_brightness")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
|
@ -84,13 +82,11 @@ async def test_brightness(
|
|||
|
||||
async def test_volume(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the LaMetric volume controls."""
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("number.frenck_s_lametric_volume")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
|
@ -135,7 +131,6 @@ async def test_volume(
|
|||
|
||||
async def test_number_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test error handling of the LaMetric numbers."""
|
||||
|
@ -166,7 +161,6 @@ async def test_number_error(
|
|||
|
||||
async def test_number_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test connection error handling of the LaMetric numbers."""
|
||||
|
|
|
@ -22,18 +22,16 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
async def test_brightness_mode(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the LaMetric brightness mode controls."""
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("select.frenck_s_lametric_brightness_mode")
|
||||
assert state
|
||||
assert (
|
||||
|
@ -76,7 +74,6 @@ async def test_brightness_mode(
|
|||
|
||||
async def test_select_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test error handling of the LaMetric selects."""
|
||||
|
@ -107,7 +104,6 @@ async def test_select_error(
|
|||
|
||||
async def test_select_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test connection error handling of the LaMetric selects."""
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""Tests for the LaMetric sensor platform."""
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.lametric.const import DOMAIN
|
||||
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
|
||||
|
@ -14,19 +14,17 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
pytestmark = pytest.mark.usefixtures(
|
||||
"entity_registry_enabled_by_default", "init_integration"
|
||||
)
|
||||
|
||||
|
||||
async def test_wifi_signal(
|
||||
hass: HomeAssistant,
|
||||
entity_registry_enabled_by_default: AsyncMock,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the LaMetric Wi-Fi sensor."""
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("sensor.frenck_s_lametric_wi_fi_signal")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
|
|
|
@ -29,12 +29,11 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
async def test_service_chart(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test the LaMetric chart service."""
|
||||
|
@ -122,7 +121,6 @@ async def test_service_chart(
|
|||
|
||||
async def test_service_message(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test the LaMetric message service."""
|
||||
|
|
|
@ -24,18 +24,18 @@ from homeassistant.exceptions import HomeAssistantError
|
|||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
async def test_bluetooth(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the LaMetric Bluetooth control."""
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("switch.frenck_s_lametric_bluetooth")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
|
@ -95,7 +95,6 @@ async def test_bluetooth(
|
|||
|
||||
async def test_switch_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test error handling of the LaMetric switches."""
|
||||
|
@ -125,7 +124,6 @@ async def test_switch_error(
|
|||
|
||||
async def test_switch_connection_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test connection error handling of the LaMetric switches."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue