mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Use MockConfigEntry in hue tests (#112149)
needed for https://github.com/home-assistant/core/pull/112141
This commit is contained in:
parent
331989de4c
commit
bef8376f83
@ -1,6 +1,6 @@
|
||||
"""Test Hue bridge."""
|
||||
import asyncio
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiohttp import client_exceptions
|
||||
from aiohue.errors import Unauthorized
|
||||
@ -12,16 +12,21 @@ from homeassistant.components.hue import bridge
|
||||
from homeassistant.components.hue.const import (
|
||||
CONF_ALLOW_HUE_GROUPS,
|
||||
CONF_ALLOW_UNREACHABLE,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_bridge_setup_v1(hass: HomeAssistant, mock_api_v1) -> None:
|
||||
"""Test a successful setup for V1 bridge."""
|
||||
config_entry = Mock()
|
||||
config_entry.data = {"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1}
|
||||
config_entry.options = {CONF_ALLOW_HUE_GROUPS: False, CONF_ALLOW_UNREACHABLE: False}
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1},
|
||||
options={CONF_ALLOW_HUE_GROUPS: False, CONF_ALLOW_UNREACHABLE: False},
|
||||
)
|
||||
|
||||
with patch.object(bridge, "HueBridgeV1", return_value=mock_api_v1), patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
@ -39,8 +44,10 @@ async def test_bridge_setup_v1(hass: HomeAssistant, mock_api_v1) -> None:
|
||||
|
||||
async def test_bridge_setup_v2(hass: HomeAssistant, mock_api_v2) -> None:
|
||||
"""Test a successful setup for V2 bridge."""
|
||||
config_entry = Mock()
|
||||
config_entry.data = {"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 2}
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 2},
|
||||
)
|
||||
|
||||
with patch.object(bridge, "HueBridgeV2", return_value=mock_api_v2), patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
@ -65,9 +72,11 @@ async def test_bridge_setup_v2(hass: HomeAssistant, mock_api_v2) -> None:
|
||||
|
||||
async def test_bridge_setup_invalid_api_key(hass: HomeAssistant) -> None:
|
||||
"""Test we start config flow if username is no longer whitelisted."""
|
||||
entry = Mock()
|
||||
entry.data = {"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1}
|
||||
entry.options = {CONF_ALLOW_HUE_GROUPS: False, CONF_ALLOW_UNREACHABLE: False}
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1},
|
||||
options={CONF_ALLOW_HUE_GROUPS: False, CONF_ALLOW_UNREACHABLE: False},
|
||||
)
|
||||
hue_bridge = bridge.HueBridge(hass, entry)
|
||||
|
||||
with patch.object(
|
||||
@ -81,9 +90,11 @@ async def test_bridge_setup_invalid_api_key(hass: HomeAssistant) -> None:
|
||||
|
||||
async def test_bridge_setup_timeout(hass: HomeAssistant) -> None:
|
||||
"""Test we retry to connect if we cannot connect."""
|
||||
entry = Mock()
|
||||
entry.data = {"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1}
|
||||
entry.options = {CONF_ALLOW_HUE_GROUPS: False, CONF_ALLOW_UNREACHABLE: False}
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1},
|
||||
options={CONF_ALLOW_HUE_GROUPS: False, CONF_ALLOW_UNREACHABLE: False},
|
||||
)
|
||||
hue_bridge = bridge.HueBridge(hass, entry)
|
||||
|
||||
with patch.object(
|
||||
@ -96,9 +107,11 @@ async def test_bridge_setup_timeout(hass: HomeAssistant) -> None:
|
||||
|
||||
async def test_reset_unloads_entry_if_setup(hass: HomeAssistant, mock_api_v1) -> None:
|
||||
"""Test calling reset while the entry has been setup."""
|
||||
config_entry = Mock()
|
||||
config_entry.data = {"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1}
|
||||
config_entry.options = {CONF_ALLOW_HUE_GROUPS: False, CONF_ALLOW_UNREACHABLE: False}
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1},
|
||||
options={CONF_ALLOW_HUE_GROUPS: False, CONF_ALLOW_UNREACHABLE: False},
|
||||
)
|
||||
|
||||
with patch.object(bridge, "HueBridgeV1", return_value=mock_api_v1), patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
@ -122,9 +135,11 @@ async def test_reset_unloads_entry_if_setup(hass: HomeAssistant, mock_api_v1) ->
|
||||
|
||||
async def test_handle_unauthorized(hass: HomeAssistant, mock_api_v1) -> None:
|
||||
"""Test handling an unauthorized error on update."""
|
||||
config_entry = Mock(async_setup=AsyncMock())
|
||||
config_entry.data = {"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1}
|
||||
config_entry.options = {CONF_ALLOW_HUE_GROUPS: False, CONF_ALLOW_UNREACHABLE: False}
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1},
|
||||
options={CONF_ALLOW_HUE_GROUPS: False, CONF_ALLOW_UNREACHABLE: False},
|
||||
)
|
||||
|
||||
with patch.object(bridge, "HueBridgeV1", return_value=mock_api_v1):
|
||||
hue_bridge = bridge.HueBridge(hass, config_entry)
|
||||
|
Loading…
x
Reference in New Issue
Block a user