Add missing mock in gree config flow tests (#89450)
parent
3c27f9ea7d
commit
adfd263635
|
@ -1,11 +1,21 @@
|
|||
"""Pytest module configuration."""
|
||||
from unittest.mock import patch
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from .common import FakeDiscovery, build_device_mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
||||
"""Override async_setup_entry."""
|
||||
with patch(
|
||||
"homeassistant.components.gree.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
yield mock_setup_entry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, name="discovery")
|
||||
def discovery_fixture():
|
||||
"""Patch the discovery object."""
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Tests for the Gree Integration."""
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.gree.const import DOMAIN as GREE_DOMAIN
|
||||
|
@ -7,15 +9,15 @@ from homeassistant.core import HomeAssistant
|
|||
|
||||
from .common import FakeDiscovery
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
|
||||
@patch("homeassistant.components.gree.config_flow.DISCOVERY_TIMEOUT", 0)
|
||||
async def test_creating_entry_sets_up_climate(hass: HomeAssistant) -> None:
|
||||
async def test_creating_entry_sets_up_climate(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
"""Test setting up Gree creates the climate components."""
|
||||
with patch(
|
||||
"homeassistant.components.gree.climate.async_setup_entry", return_value=True
|
||||
) as setup, patch(
|
||||
"homeassistant.components.gree.bridge.Discovery", return_value=FakeDiscovery()
|
||||
), patch(
|
||||
"homeassistant.components.gree.config_flow.Discovery",
|
||||
return_value=FakeDiscovery(),
|
||||
):
|
||||
|
@ -31,22 +33,19 @@ async def test_creating_entry_sets_up_climate(hass: HomeAssistant) -> None:
|
|||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
@patch("homeassistant.components.gree.config_flow.DISCOVERY_TIMEOUT", 0)
|
||||
async def test_creating_entry_has_no_devices(hass: HomeAssistant) -> None:
|
||||
async def test_creating_entry_has_no_devices(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
"""Test setting up Gree creates the climate components."""
|
||||
with patch(
|
||||
"homeassistant.components.gree.climate.async_setup_entry", return_value=True
|
||||
) as setup, patch(
|
||||
"homeassistant.components.gree.bridge.Discovery", return_value=FakeDiscovery()
|
||||
) as discovery, patch(
|
||||
"homeassistant.components.gree.config_flow.Discovery",
|
||||
return_value=FakeDiscovery(),
|
||||
) as discovery2:
|
||||
) as discovery:
|
||||
discovery.return_value.mock_devices = []
|
||||
discovery2.return_value.mock_devices = []
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
GREE_DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
|
@ -60,4 +59,4 @@ async def test_creating_entry_has_no_devices(hass: HomeAssistant) -> None:
|
|||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(setup.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
|
|
Loading…
Reference in New Issue