mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add missing mock in landisgyr config flow tests (#89513)
This commit is contained in:
parent
75bca76e68
commit
f674559a71
15
tests/components/landisgyr_heat_meter/conftest.py
Normal file
15
tests/components/landisgyr_heat_meter/conftest.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
"""Define fixtures for Landis + Gyr Heat Meter tests."""
|
||||||
|
from collections.abc import Generator
|
||||||
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
||||||
|
"""Override async_setup_entry."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.landisgyr_heat_meter.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
) as mock_setup_entry:
|
||||||
|
yield mock_setup_entry
|
@ -2,6 +2,7 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
import serial
|
import serial
|
||||||
import serial.tools.list_ports
|
import serial.tools.list_ports
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ from tests.common import MockConfigEntry
|
|||||||
|
|
||||||
API_HEAT_METER_SERVICE = "homeassistant.components.landisgyr_heat_meter.config_flow.ultraheat_api.HeatMeterService"
|
API_HEAT_METER_SERVICE = "homeassistant.components.landisgyr_heat_meter.config_flow.ultraheat_api.HeatMeterService"
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||||
|
|
||||||
|
|
||||||
def mock_serial_port():
|
def mock_serial_port():
|
||||||
"""Mock of a serial port."""
|
"""Mock of a serial port."""
|
||||||
@ -57,13 +60,9 @@ async def test_manual_entry(mock_heat_meter, hass: HomeAssistant) -> None:
|
|||||||
assert result["step_id"] == "setup_serial_manual_path"
|
assert result["step_id"] == "setup_serial_manual_path"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
"homeassistant.components.landisgyr_heat_meter.async_setup_entry",
|
result["flow_id"], {"device": "/dev/ttyUSB0"}
|
||||||
return_value=True,
|
)
|
||||||
):
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
|
||||||
result["flow_id"], {"device": "/dev/ttyUSB0"}
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == "LUGCUH50"
|
assert result["title"] == "LUGCUH50"
|
||||||
@ -122,13 +121,9 @@ async def test_manual_entry_fail(mock_heat_meter, hass: HomeAssistant) -> None:
|
|||||||
assert result["step_id"] == "setup_serial_manual_path"
|
assert result["step_id"] == "setup_serial_manual_path"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
"homeassistant.components.landisgyr_heat_meter.async_setup_entry",
|
result["flow_id"], {"device": "/dev/ttyUSB0"}
|
||||||
return_value=True,
|
)
|
||||||
):
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
|
||||||
result["flow_id"], {"device": "/dev/ttyUSB0"}
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.FORM
|
assert result["type"] == FlowResultType.FORM
|
||||||
assert result["step_id"] == "setup_serial_manual_path"
|
assert result["step_id"] == "setup_serial_manual_path"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user