mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 02:37:50 +00:00
Prevent 3rd party lib from opening sockets in glances tests (#56345)
This commit is contained in:
parent
be0819b456
commit
39bc127dd6
@ -1,13 +1,13 @@
|
|||||||
"""Tests for Glances config flow."""
|
"""Tests for Glances config flow."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from glances_api import Glances
|
from glances_api import exceptions
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components import glances
|
from homeassistant.components import glances
|
||||||
from homeassistant.const import CONF_SCAN_INTERVAL
|
from homeassistant.const import CONF_SCAN_INTERVAL
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_coro
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
NAME = "Glances"
|
NAME = "Glances"
|
||||||
HOST = "0.0.0.0"
|
HOST = "0.0.0.0"
|
||||||
@ -38,9 +38,7 @@ async def test_form(hass):
|
|||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
with patch("glances_api.Glances"), patch.object(
|
with patch("homeassistant.components.glances.Glances.get_data", autospec=True):
|
||||||
Glances, "get_data", return_value=mock_coro()
|
|
||||||
):
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], user_input=DEMO_USER_INPUT
|
result["flow_id"], user_input=DEMO_USER_INPUT
|
||||||
@ -54,7 +52,10 @@ async def test_form(hass):
|
|||||||
async def test_form_cannot_connect(hass):
|
async def test_form_cannot_connect(hass):
|
||||||
"""Test to return error if we cannot connect."""
|
"""Test to return error if we cannot connect."""
|
||||||
|
|
||||||
with patch("glances_api.Glances"):
|
with patch(
|
||||||
|
"homeassistant.components.glances.Glances.get_data",
|
||||||
|
side_effect=exceptions.GlancesApiConnectionError,
|
||||||
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
glances.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
glances.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user