Prevent 3rd party lib from opening sockets in freedompro tests (#55596)
parent
348bdca647
commit
2e5c1236f9
|
@ -9,6 +9,22 @@ from tests.common import MockConfigEntry
|
||||||
from tests.components.freedompro.const import DEVICES, DEVICES_STATE
|
from tests.components.freedompro.const import DEVICES, DEVICES_STATE
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def mock_freedompro():
|
||||||
|
"""Mock freedompro get_list and get_states."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.freedompro.get_list",
|
||||||
|
return_value={
|
||||||
|
"state": True,
|
||||||
|
"devices": DEVICES,
|
||||||
|
},
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.freedompro.get_states",
|
||||||
|
return_value=DEVICES_STATE,
|
||||||
|
):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def init_integration(hass) -> MockConfigEntry:
|
async def init_integration(hass) -> MockConfigEntry:
|
||||||
"""Set up the Freedompro integration in Home Assistant."""
|
"""Set up the Freedompro integration in Home Assistant."""
|
||||||
|
@ -21,19 +37,9 @@ async def init_integration(hass) -> MockConfigEntry:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
entry.add_to_hass(hass)
|
||||||
"homeassistant.components.freedompro.get_list",
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
return_value={
|
await hass.async_block_till_done()
|
||||||
"state": True,
|
|
||||||
"devices": DEVICES,
|
|
||||||
},
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.freedompro.get_states",
|
|
||||||
return_value=DEVICES_STATE,
|
|
||||||
):
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ async def test_show_form(hass):
|
||||||
async def test_invalid_auth(hass):
|
async def test_invalid_auth(hass):
|
||||||
"""Test that errors are shown when API key is invalid."""
|
"""Test that errors are shown when API key is invalid."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.freedompro.config_flow.list",
|
"homeassistant.components.freedompro.config_flow.get_list",
|
||||||
return_value={
|
return_value={
|
||||||
"state": False,
|
"state": False,
|
||||||
"code": -201,
|
"code": -201,
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
"""Tests for the Freedompro light."""
|
"""Tests for the Freedompro light."""
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
|
@ -9,6 +13,13 @@ from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, STATE_OFF, STA
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def mock_freedompro_put_state():
|
||||||
|
"""Mock freedompro put_state."""
|
||||||
|
with patch("homeassistant.components.freedompro.light.put_state"):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
async def test_light_get_state(hass, init_integration):
|
async def test_light_get_state(hass, init_integration):
|
||||||
"""Test states of the light."""
|
"""Test states of the light."""
|
||||||
init_integration
|
init_integration
|
||||||
|
|
Loading…
Reference in New Issue