Add missing mock in landisgyr config flow tests (#89513)

This commit is contained in:
epenet 2023-03-10 16:04:45 +01:00 committed by GitHub
parent 75bca76e68
commit f674559a71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 14 deletions

View 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

View File

@ -2,6 +2,7 @@
from dataclasses import dataclass
from unittest.mock import patch
import pytest
import serial
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"
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
def mock_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["errors"] == {}
with patch(
"homeassistant.components.landisgyr_heat_meter.async_setup_entry",
return_value=True,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"device": "/dev/ttyUSB0"}
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"device": "/dev/ttyUSB0"}
)
assert result["type"] == FlowResultType.CREATE_ENTRY
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["errors"] == {}
with patch(
"homeassistant.components.landisgyr_heat_meter.async_setup_entry",
return_value=True,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"device": "/dev/ttyUSB0"}
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"device": "/dev/ttyUSB0"}
)
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "setup_serial_manual_path"