Use built-in test helpers on 3.8 (#34901)
This commit is contained in:
parent
6b16c34fd0
commit
ec47216388
303 changed files with 1163 additions and 1320 deletions
|
@ -75,12 +75,9 @@ class HassIOAddonPanel(HomeAssistantView):
|
|||
return {}
|
||||
|
||||
|
||||
def _register_panel(hass, addon, data):
|
||||
"""Init coroutine to register the panel.
|
||||
|
||||
Return coroutine.
|
||||
"""
|
||||
return hass.components.panel_custom.async_register_panel(
|
||||
async def _register_panel(hass, addon, data):
|
||||
"""Init coroutine to register the panel."""
|
||||
await hass.components.panel_custom.async_register_panel(
|
||||
frontend_url_path=addon,
|
||||
webcomponent_name="hassio-main",
|
||||
sidebar_title=data[ATTR_TITLE],
|
||||
|
|
|
@ -484,7 +484,7 @@ class HomeKit:
|
|||
)
|
||||
|
||||
_LOGGER.debug("Driver start")
|
||||
self.hass.async_add_executor_job(self.driver.start)
|
||||
self.hass.add_job(self.driver.start)
|
||||
self.status = STATUS_RUNNING
|
||||
|
||||
async def async_stop(self, *args):
|
||||
|
|
|
@ -165,7 +165,7 @@ class HomeAccessory(Accessory):
|
|||
Run inside the Home Assistant event loop.
|
||||
"""
|
||||
state = self.hass.states.get(self.entity_id)
|
||||
self.hass.async_add_executor_job(self.update_state_callback, None, None, state)
|
||||
self.hass.async_add_job(self.update_state_callback, None, None, state)
|
||||
async_track_state_change(self.hass, self.entity_id, self.update_state_callback)
|
||||
|
||||
battery_charging_state = None
|
||||
|
|
|
@ -99,15 +99,6 @@ class SmhiWeather(WeatherEntity):
|
|||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
async def async_update(self) -> None:
|
||||
"""Refresh the forecast data from SMHI weather API."""
|
||||
|
||||
def fail():
|
||||
"""Postpone updates."""
|
||||
self._fail_count += 1
|
||||
if self._fail_count < 3:
|
||||
self.hass.helpers.event.async_call_later(
|
||||
RETRY_TIMEOUT, self.retry_update()
|
||||
)
|
||||
|
||||
try:
|
||||
with async_timeout.timeout(10):
|
||||
self._forecasts = await self.get_weather_forecast()
|
||||
|
@ -115,11 +106,15 @@ class SmhiWeather(WeatherEntity):
|
|||
|
||||
except (asyncio.TimeoutError, SmhiForecastException):
|
||||
_LOGGER.error("Failed to connect to SMHI API, retry in 5 minutes")
|
||||
fail()
|
||||
self._fail_count += 1
|
||||
if self._fail_count < 3:
|
||||
self.hass.helpers.event.async_call_later(
|
||||
RETRY_TIMEOUT, self.retry_update
|
||||
)
|
||||
|
||||
async def retry_update(self):
|
||||
async def retry_update(self, _):
|
||||
"""Retry refresh weather forecast."""
|
||||
self.async_update()
|
||||
await self.async_update()
|
||||
|
||||
async def get_weather_forecast(self) -> []:
|
||||
"""Return the current forecasts from SMHI API."""
|
||||
|
|
|
@ -90,8 +90,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
controller.start()
|
||||
|
||||
hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
lambda event: hass.async_add_executor_job(controller.stop),
|
||||
EVENT_HOMEASSISTANT_STOP, lambda event: controller.stop()
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
"""Test the NEW_NAME config flow."""
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.NEW_DOMAIN.config_flow import CannotConnect, InvalidAuth
|
||||
from homeassistant.components.NEW_DOMAIN.const import DOMAIN
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
async def test_form(hass):
|
||||
"""Test we get the form."""
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""Test the NEW_NAME config flow."""
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.NEW_DOMAIN.const import (
|
||||
DOMAIN,
|
||||
|
@ -9,6 +7,8 @@ from homeassistant.components.NEW_DOMAIN.const import (
|
|||
)
|
||||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
CLIENT_ID = "1234"
|
||||
CLIENT_SECRET = "5678"
|
||||
|
||||
|
|
8
tests/async_mock.py
Normal file
8
tests/async_mock.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
"""Mock utilities that are async aware."""
|
||||
import sys
|
||||
|
||||
if sys.version_info[:2] < (3, 8):
|
||||
from asynctest.mock import * # noqa
|
||||
from asynctest.mock import CoroutineMock as AsyncMock # noqa
|
||||
else:
|
||||
from unittest.mock import * # noqa
|
|
@ -1,7 +1,6 @@
|
|||
"""Tests for the command_line auth provider."""
|
||||
|
||||
import os
|
||||
from unittest.mock import Mock
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
@ -11,7 +10,7 @@ from homeassistant.auth import AuthManager, auth_store, models as auth_models
|
|||
from homeassistant.auth.providers import command_line
|
||||
from homeassistant.const import CONF_TYPE
|
||||
|
||||
from tests.common import mock_coro
|
||||
from tests.async_mock import AsyncMock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -63,7 +62,7 @@ async def test_match_existing_credentials(store, provider):
|
|||
data={"username": "good-user"},
|
||||
is_new=False,
|
||||
)
|
||||
provider.async_credentials = Mock(return_value=mock_coro([existing]))
|
||||
provider.async_credentials = AsyncMock(return_value=[existing])
|
||||
credentials = await provider.async_get_or_create_credentials(
|
||||
{"username": "good-user", "password": "irrelevant"}
|
||||
)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Test the Home Assistant local auth provider."""
|
||||
import asyncio
|
||||
|
||||
from asynctest import Mock, patch
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -12,6 +11,8 @@ from homeassistant.auth.providers import (
|
|||
homeassistant as hass_auth,
|
||||
)
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def data(hass):
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Tests for the insecure example auth provider."""
|
||||
from unittest.mock import Mock
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
@ -7,7 +6,7 @@ import pytest
|
|||
from homeassistant.auth import AuthManager, auth_store, models as auth_models
|
||||
from homeassistant.auth.providers import insecure_example
|
||||
|
||||
from tests.common import mock_coro
|
||||
from tests.async_mock import AsyncMock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -63,7 +62,7 @@ async def test_match_existing_credentials(store, provider):
|
|||
data={"username": "user-test"},
|
||||
is_new=False,
|
||||
)
|
||||
provider.async_credentials = Mock(return_value=mock_coro([existing]))
|
||||
provider.async_credentials = AsyncMock(return_value=[existing])
|
||||
credentials = await provider.async_get_or_create_credentials(
|
||||
{"username": "user-test", "password": "password-test"}
|
||||
)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
"""Tests for the auth store."""
|
||||
import asyncio
|
||||
|
||||
import asynctest
|
||||
|
||||
from homeassistant.auth import auth_store
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
async def test_loading_no_group_data_format(hass, hass_storage):
|
||||
"""Test we correctly load old data without any groups."""
|
||||
|
@ -229,12 +229,12 @@ async def test_system_groups_store_id_and_name(hass, hass_storage):
|
|||
async def test_loading_race_condition(hass):
|
||||
"""Test only one storage load called when concurrent loading occurred ."""
|
||||
store = auth_store.AuthStore(hass)
|
||||
with asynctest.patch(
|
||||
with patch(
|
||||
"homeassistant.helpers.entity_registry.async_get_registry"
|
||||
) as mock_ent_registry, asynctest.patch(
|
||||
) as mock_ent_registry, patch(
|
||||
"homeassistant.helpers.device_registry.async_get_registry"
|
||||
) as mock_dev_registry, asynctest.patch(
|
||||
"homeassistant.helpers.storage.Store.async_load"
|
||||
) as mock_dev_registry, patch(
|
||||
"homeassistant.helpers.storage.Store.async_load", return_value=None
|
||||
) as mock_load:
|
||||
results = await asyncio.gather(store.async_get_users(), store.async_get_users())
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import threading
|
|||
import uuid
|
||||
|
||||
from aiohttp.test_utils import unused_port as get_test_instance_port # noqa
|
||||
from asynctest import MagicMock, Mock, patch
|
||||
|
||||
from homeassistant import auth, config_entries, core as ha, loader
|
||||
from homeassistant.auth import (
|
||||
|
@ -60,6 +59,8 @@ import homeassistant.util.dt as date_util
|
|||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
import homeassistant.util.yaml.loader as yaml_loader
|
||||
|
||||
from tests.async_mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
INSTANCES = []
|
||||
CLIENT_ID = "https://example.com/app"
|
||||
|
@ -159,20 +160,37 @@ async def async_test_home_assistant(loop):
|
|||
|
||||
def async_add_job(target, *args):
|
||||
"""Add job."""
|
||||
if isinstance(target, Mock):
|
||||
return mock_coro(target(*args))
|
||||
check_target = target
|
||||
while isinstance(check_target, ft.partial):
|
||||
check_target = check_target.func
|
||||
|
||||
if isinstance(check_target, Mock) and not isinstance(target, AsyncMock):
|
||||
fut = asyncio.Future()
|
||||
fut.set_result(target(*args))
|
||||
return fut
|
||||
|
||||
return orig_async_add_job(target, *args)
|
||||
|
||||
def async_add_executor_job(target, *args):
|
||||
"""Add executor job."""
|
||||
if isinstance(target, Mock):
|
||||
return mock_coro(target(*args))
|
||||
check_target = target
|
||||
while isinstance(check_target, ft.partial):
|
||||
check_target = check_target.func
|
||||
|
||||
if isinstance(check_target, Mock):
|
||||
fut = asyncio.Future()
|
||||
fut.set_result(target(*args))
|
||||
return fut
|
||||
|
||||
return orig_async_add_executor_job(target, *args)
|
||||
|
||||
def async_create_task(coroutine):
|
||||
"""Create task."""
|
||||
if isinstance(coroutine, Mock):
|
||||
return mock_coro()
|
||||
if isinstance(coroutine, Mock) and not isinstance(coroutine, AsyncMock):
|
||||
fut = asyncio.Future()
|
||||
fut.set_result(None)
|
||||
return fut
|
||||
|
||||
return orig_async_create_task(coroutine)
|
||||
|
||||
hass.async_add_job = async_add_job
|
||||
|
@ -311,15 +329,16 @@ async def async_mock_mqtt_component(hass, config=None):
|
|||
if config is None:
|
||||
config = {mqtt.CONF_BROKER: "mock-broker"}
|
||||
|
||||
async def _async_fire_mqtt_message(topic, payload, qos, retain):
|
||||
@ha.callback
|
||||
def _async_fire_mqtt_message(topic, payload, qos, retain):
|
||||
async_fire_mqtt_message(hass, topic, payload, qos, retain)
|
||||
|
||||
with patch("paho.mqtt.client.Client") as mock_client:
|
||||
mock_client().connect.return_value = 0
|
||||
mock_client().subscribe.return_value = (0, 0)
|
||||
mock_client().unsubscribe.return_value = (0, 0)
|
||||
mock_client().publish.return_value = (0, 0)
|
||||
mock_client().publish.side_effect = _async_fire_mqtt_message
|
||||
mock_client = mock_client.return_value
|
||||
mock_client.connect.return_value = 0
|
||||
mock_client.subscribe.return_value = (0, 0)
|
||||
mock_client.unsubscribe.return_value = (0, 0)
|
||||
mock_client.publish.side_effect = _async_fire_mqtt_message
|
||||
|
||||
result = await async_setup_component(hass, mqtt.DOMAIN, {mqtt.DOMAIN: config})
|
||||
assert result
|
||||
|
@ -503,7 +522,7 @@ class MockModule:
|
|||
self.async_setup = async_setup
|
||||
|
||||
if setup is None and async_setup is None:
|
||||
self.async_setup = mock_coro_func(True)
|
||||
self.async_setup = AsyncMock(return_value=True)
|
||||
|
||||
if async_setup_entry is not None:
|
||||
self.async_setup_entry = async_setup_entry
|
||||
|
@ -561,7 +580,7 @@ class MockPlatform:
|
|||
self.async_setup_entry = async_setup_entry
|
||||
|
||||
if setup_platform is None and async_setup_platform is None:
|
||||
self.async_setup_platform = mock_coro_func()
|
||||
self.async_setup_platform = AsyncMock(return_value=None)
|
||||
|
||||
|
||||
class MockEntityPlatform(entity_platform.EntityPlatform):
|
||||
|
@ -731,14 +750,10 @@ def mock_coro(return_value=None, exception=None):
|
|||
def mock_coro_func(return_value=None, exception=None):
|
||||
"""Return a method to create a coro function that returns a value."""
|
||||
|
||||
@asyncio.coroutine
|
||||
def coro(*args, **kwargs):
|
||||
"""Fake coroutine."""
|
||||
if exception:
|
||||
raise exception
|
||||
return return_value
|
||||
if exception:
|
||||
return AsyncMock(side_effect=exception)
|
||||
|
||||
return coro
|
||||
return AsyncMock(return_value=return_value)
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Tests for the AdGuard Home config flow."""
|
||||
from unittest.mock import patch
|
||||
|
||||
import aiohttp
|
||||
|
||||
|
@ -15,7 +14,8 @@ from homeassistant.const import (
|
|||
CONF_VERIFY_SSL,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
FIXTURE_USER_INPUT = {
|
||||
CONF_HOST: "127.0.0.1",
|
||||
|
@ -156,22 +156,16 @@ async def test_hassio_update_instance_running(hass, aioclient_mock):
|
|||
entry.add_to_hass(hass)
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries,
|
||||
"async_forward_entry_setup",
|
||||
side_effect=lambda *_: mock_coro(True),
|
||||
hass.config_entries, "async_forward_entry_setup", return_value=True,
|
||||
) as mock_load:
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert entry.state == config_entries.ENTRY_STATE_LOADED
|
||||
assert len(mock_load.mock_calls) == 2
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries,
|
||||
"async_forward_entry_unload",
|
||||
side_effect=lambda *_: mock_coro(True),
|
||||
hass.config_entries, "async_forward_entry_unload", return_value=True,
|
||||
) as mock_unload, patch.object(
|
||||
hass.config_entries,
|
||||
"async_forward_entry_setup",
|
||||
side_effect=lambda *_: mock_coro(True),
|
||||
hass.config_entries, "async_forward_entry_setup", return_value=True,
|
||||
) as mock_load:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"adguard",
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import json
|
||||
|
||||
from airly.exceptions import AirlyError
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.airly.const import DOMAIN
|
||||
|
@ -15,6 +14,7 @@ from homeassistant.const import (
|
|||
HTTP_FORBIDDEN,
|
||||
)
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
CONFIG = {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Define tests for the AirVisual config flow."""
|
||||
from asynctest import patch
|
||||
from pyairvisual.errors import InvalidKeyError, NodeProError
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
|
@ -21,6 +20,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
"""Test the Almond config flow."""
|
||||
import asyncio
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow, setup
|
||||
from homeassistant.components.almond import config_flow
|
||||
from homeassistant.components.almond.const import DOMAIN
|
||||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
CLIENT_ID_VALUE = "1234"
|
||||
CLIENT_SECRET_VALUE = "5678"
|
||||
|
@ -16,7 +15,7 @@ CLIENT_SECRET_VALUE = "5678"
|
|||
|
||||
async def test_import(hass):
|
||||
"""Test that we can import a config entry."""
|
||||
with patch("pyalmond.WebAlmondAPI.async_list_apps", side_effect=mock_coro):
|
||||
with patch("pyalmond.WebAlmondAPI.async_list_apps"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"almond",
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
"""Tests for the Ambiclimate config flow."""
|
||||
import ambiclimate
|
||||
from asynctest import Mock, patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.ambiclimate import config_flow
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import aiohttp
|
||||
|
||||
from tests.common import mock_coro
|
||||
from tests.async_mock import AsyncMock, patch
|
||||
|
||||
|
||||
async def init_config_flow(hass):
|
||||
|
@ -67,9 +66,7 @@ async def test_full_flow_implementation(hass):
|
|||
assert "response_type=code" in url
|
||||
assert "redirect_uri=https%3A%2F%2Fhass.com%2Fapi%2Fambiclimate" in url
|
||||
|
||||
with patch(
|
||||
"ambiclimate.AmbiclimateOAuth.get_access_token", return_value=mock_coro("test")
|
||||
):
|
||||
with patch("ambiclimate.AmbiclimateOAuth.get_access_token", return_value="test"):
|
||||
result = await flow.async_step_code("123ABC")
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "Ambiclimate"
|
||||
|
@ -77,9 +74,7 @@ async def test_full_flow_implementation(hass):
|
|||
assert result["data"]["client_secret"] == "secret"
|
||||
assert result["data"]["client_id"] == "id"
|
||||
|
||||
with patch(
|
||||
"ambiclimate.AmbiclimateOAuth.get_access_token", return_value=mock_coro(None)
|
||||
):
|
||||
with patch("ambiclimate.AmbiclimateOAuth.get_access_token", return_value=None):
|
||||
result = await flow.async_step_code("123ABC")
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
|
||||
|
@ -96,9 +91,7 @@ async def test_abort_invalid_code(hass):
|
|||
config_flow.register_flow_implementation(hass, None, None)
|
||||
flow = await init_config_flow(hass)
|
||||
|
||||
with patch(
|
||||
"ambiclimate.AmbiclimateOAuth.get_access_token", return_value=mock_coro(None)
|
||||
):
|
||||
with patch("ambiclimate.AmbiclimateOAuth.get_access_token", return_value=None):
|
||||
result = await flow.async_step_code("invalid")
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "access_token"
|
||||
|
@ -118,7 +111,7 @@ async def test_already_setup(hass):
|
|||
|
||||
async def test_view(hass):
|
||||
"""Test view."""
|
||||
hass.config_entries.flow.async_init = Mock()
|
||||
hass.config_entries.flow.async_init = AsyncMock()
|
||||
|
||||
request = aiohttp.MockRequest(b"", query_string="code=test_code")
|
||||
request.app = {"hass": hass}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Tests for the arcam_fmj component."""
|
||||
from arcam.fmj.client import Client
|
||||
from arcam.fmj.state import State
|
||||
from asynctest import Mock
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.arcam_fmj import DEVICE_SCHEMA
|
||||
|
@ -9,6 +8,8 @@ from homeassistant.components.arcam_fmj.const import DOMAIN
|
|||
from homeassistant.components.arcam_fmj.media_player import ArcamFmj
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
|
||||
from tests.async_mock import Mock
|
||||
|
||||
MOCK_HOST = "127.0.0.1"
|
||||
MOCK_PORT = 1234
|
||||
MOCK_TURN_ON = {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from math import isclose
|
||||
|
||||
from arcam.fmj import DecodeMode2CH, DecodeModeMCH, IncomingAudioFormat, SourceCodes
|
||||
from asynctest.mock import ANY, MagicMock, Mock, PropertyMock, patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
|
||||
|
@ -10,6 +9,8 @@ from homeassistant.core import HomeAssistant
|
|||
|
||||
from .conftest import MOCK_ENTITY_ID, MOCK_HOST, MOCK_NAME, MOCK_PORT
|
||||
|
||||
from tests.async_mock import ANY, MagicMock, Mock, PropertyMock, patch
|
||||
|
||||
MOCK_TURN_ON = {
|
||||
"service": "switch.turn_on",
|
||||
"data": {"entity_id": "switch.test"},
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from datetime import datetime, timedelta
|
||||
|
||||
from aioasuswrt.asuswrt import Device
|
||||
from asynctest import CoroutineMock, patch
|
||||
|
||||
from homeassistant.components import sensor
|
||||
from homeassistant.components.asuswrt import (
|
||||
|
@ -20,6 +19,7 @@ from homeassistant.setup import async_setup_component
|
|||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.async_mock import AsyncMock, patch
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
VALID_CONFIG_ROUTER_SSH = {
|
||||
|
@ -54,10 +54,10 @@ MOCK_CURRENT_TRANSFER_RATES = [20000000, 10000000]
|
|||
async def test_sensors(hass: HomeAssistant):
|
||||
"""Test creating an AsusWRT sensor."""
|
||||
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
|
||||
AsusWrt().connection.async_connect = CoroutineMock()
|
||||
AsusWrt().async_get_connected_devices = CoroutineMock(return_value=MOCK_DEVICES)
|
||||
AsusWrt().async_get_bytes_total = CoroutineMock(return_value=MOCK_BYTES_TOTAL)
|
||||
AsusWrt().async_get_current_transfer_rates = CoroutineMock(
|
||||
AsusWrt().connection.async_connect = AsyncMock()
|
||||
AsusWrt().async_get_connected_devices = AsyncMock(return_value=MOCK_DEVICES)
|
||||
AsusWrt().async_get_bytes_total = AsyncMock(return_value=MOCK_BYTES_TOTAL)
|
||||
AsusWrt().async_get_current_transfer_rates = AsyncMock(
|
||||
return_value=MOCK_CURRENT_TRANSFER_RATES
|
||||
)
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
"""Tests for the Atag config flow."""
|
||||
from unittest.mock import PropertyMock
|
||||
|
||||
from asynctest import patch
|
||||
from pyatag import AtagException
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.atag import DOMAIN
|
||||
from homeassistant.const import CONF_DEVICE, CONF_HOST, CONF_PORT
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
FIXTURE_USER_INPUT = {
|
||||
|
|
|
@ -3,8 +3,6 @@ import json
|
|||
import os
|
||||
import time
|
||||
|
||||
from asynctest import mock
|
||||
from asynctest.mock import CoroutineMock, MagicMock, PropertyMock
|
||||
from august.activity import (
|
||||
ACTIVITY_ACTIONS_DOOR_OPERATION,
|
||||
ACTIVITY_ACTIONS_DOORBELL_DING,
|
||||
|
@ -29,6 +27,8 @@ from homeassistant.components.august import (
|
|||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
# from tests.async_mock import AsyncMock
|
||||
from tests.async_mock import AsyncMock, MagicMock, PropertyMock, patch
|
||||
from tests.common import load_fixture
|
||||
|
||||
|
||||
|
@ -43,10 +43,8 @@ def _mock_get_config():
|
|||
}
|
||||
|
||||
|
||||
@mock.patch("homeassistant.components.august.gateway.ApiAsync")
|
||||
@mock.patch(
|
||||
"homeassistant.components.august.gateway.AuthenticatorAsync.async_authenticate"
|
||||
)
|
||||
@patch("homeassistant.components.august.gateway.ApiAsync")
|
||||
@patch("homeassistant.components.august.gateway.AuthenticatorAsync.async_authenticate")
|
||||
async def _mock_setup_august(hass, api_instance, authenticate_mock, api_mock):
|
||||
"""Set up august integration."""
|
||||
authenticate_mock.side_effect = MagicMock(
|
||||
|
@ -150,37 +148,37 @@ async def _mock_setup_august_with_api_side_effects(hass, api_call_side_effects):
|
|||
api_instance = MagicMock(name="Api")
|
||||
|
||||
if api_call_side_effects["get_lock_detail"]:
|
||||
type(api_instance).async_get_lock_detail = CoroutineMock(
|
||||
type(api_instance).async_get_lock_detail = AsyncMock(
|
||||
side_effect=api_call_side_effects["get_lock_detail"]
|
||||
)
|
||||
|
||||
if api_call_side_effects["get_operable_locks"]:
|
||||
type(api_instance).async_get_operable_locks = CoroutineMock(
|
||||
type(api_instance).async_get_operable_locks = AsyncMock(
|
||||
side_effect=api_call_side_effects["get_operable_locks"]
|
||||
)
|
||||
|
||||
if api_call_side_effects["get_doorbells"]:
|
||||
type(api_instance).async_get_doorbells = CoroutineMock(
|
||||
type(api_instance).async_get_doorbells = AsyncMock(
|
||||
side_effect=api_call_side_effects["get_doorbells"]
|
||||
)
|
||||
|
||||
if api_call_side_effects["get_doorbell_detail"]:
|
||||
type(api_instance).async_get_doorbell_detail = CoroutineMock(
|
||||
type(api_instance).async_get_doorbell_detail = AsyncMock(
|
||||
side_effect=api_call_side_effects["get_doorbell_detail"]
|
||||
)
|
||||
|
||||
if api_call_side_effects["get_house_activities"]:
|
||||
type(api_instance).async_get_house_activities = CoroutineMock(
|
||||
type(api_instance).async_get_house_activities = AsyncMock(
|
||||
side_effect=api_call_side_effects["get_house_activities"]
|
||||
)
|
||||
|
||||
if api_call_side_effects["lock_return_activities"]:
|
||||
type(api_instance).async_lock_return_activities = CoroutineMock(
|
||||
type(api_instance).async_lock_return_activities = AsyncMock(
|
||||
side_effect=api_call_side_effects["lock_return_activities"]
|
||||
)
|
||||
|
||||
if api_call_side_effects["unlock_return_activities"]:
|
||||
type(api_instance).async_unlock_return_activities = CoroutineMock(
|
||||
type(api_instance).async_unlock_return_activities = AsyncMock(
|
||||
side_effect=api_call_side_effects["unlock_return_activities"]
|
||||
)
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
"""The camera tests for the august platform."""
|
||||
|
||||
from asynctest import mock
|
||||
|
||||
from homeassistant.const import STATE_IDLE
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.components.august.mocks import (
|
||||
_create_august_with_devices,
|
||||
_mock_doorbell_from_fixture,
|
||||
|
@ -14,7 +13,7 @@ async def test_create_doorbell(hass, aiohttp_client):
|
|||
"""Test creation of a doorbell."""
|
||||
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
|
||||
|
||||
with mock.patch.object(
|
||||
with patch.object(
|
||||
doorbell_one, "async_get_doorbell_image", create=False, return_value="image"
|
||||
):
|
||||
await _create_august_with_devices(hass, [doorbell_one])
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Test the August config flow."""
|
||||
from asynctest import patch
|
||||
from august.authenticator import ValidationResult
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
|
@ -17,6 +16,8 @@ from homeassistant.components.august.exceptions import (
|
|||
)
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
async def test_form(hass):
|
||||
"""Test we get the form."""
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
"""The gateway tests for the august platform."""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from asynctest import mock
|
||||
|
||||
from homeassistant.components.august.const import DOMAIN
|
||||
from homeassistant.components.august.gateway import AugustGateway
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.components.august.mocks import _mock_august_authentication, _mock_get_config
|
||||
|
||||
|
||||
|
@ -14,11 +13,9 @@ async def test_refresh_access_token(hass):
|
|||
await _patched_refresh_access_token(hass, "new_token", 5678)
|
||||
|
||||
|
||||
@mock.patch(
|
||||
"homeassistant.components.august.gateway.AuthenticatorAsync.async_authenticate"
|
||||
)
|
||||
@mock.patch("homeassistant.components.august.gateway.AuthenticatorAsync.should_refresh")
|
||||
@mock.patch(
|
||||
@patch("homeassistant.components.august.gateway.AuthenticatorAsync.async_authenticate")
|
||||
@patch("homeassistant.components.august.gateway.AuthenticatorAsync.should_refresh")
|
||||
@patch(
|
||||
"homeassistant.components.august.gateway.AuthenticatorAsync.async_refresh_access_token"
|
||||
)
|
||||
async def _patched_refresh_access_token(
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""The tests for the august platform."""
|
||||
import asyncio
|
||||
|
||||
from asynctest import patch
|
||||
from august.exceptions import AugustApiAIOHTTPError
|
||||
|
||||
from homeassistant import setup
|
||||
|
@ -27,6 +26,7 @@ from homeassistant.const import (
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.august.mocks import (
|
||||
_create_august_with_devices,
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
"""Tests for the client validator."""
|
||||
import asyncio
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.auth import indieauth
|
||||
|
||||
from tests.common import mock_coro
|
||||
from tests.async_mock import patch
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
|
@ -113,9 +112,7 @@ async def test_verify_redirect_uri():
|
|||
None, "http://ex.com", "http://ex.com/callback"
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
indieauth, "fetch_redirect_uris", side_effect=lambda *_: mock_coro([])
|
||||
):
|
||||
with patch.object(indieauth, "fetch_redirect_uris", return_value=[]):
|
||||
# Different domain
|
||||
assert not await indieauth.verify_redirect_uri(
|
||||
None, "http://ex.com", "http://different.com/callback"
|
||||
|
@ -174,9 +171,7 @@ async def test_find_link_tag_max_size(hass, mock_session):
|
|||
)
|
||||
async def test_verify_redirect_uri_android_ios(client_id):
|
||||
"""Test that we verify redirect uri correctly for Android/iOS."""
|
||||
with patch.object(
|
||||
indieauth, "fetch_redirect_uris", side_effect=lambda *_: mock_coro([])
|
||||
):
|
||||
with patch.object(indieauth, "fetch_redirect_uris", return_value=[]):
|
||||
assert await indieauth.verify_redirect_uri(
|
||||
None, client_id, "homeassistant://auth-callback"
|
||||
)
|
||||
|
|
|
@ -3,11 +3,12 @@ from datetime import datetime
|
|||
import logging
|
||||
|
||||
import aioautomatic
|
||||
from asynctest import MagicMock, patch
|
||||
|
||||
from homeassistant.components.automatic.device_tracker import async_setup_scanner
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import MagicMock, patch
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
"""The tests for the Event automation."""
|
||||
from unittest.mock import Mock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.core import CoreState
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import async_mock_service, mock_coro
|
||||
from tests.async_mock import AsyncMock
|
||||
from tests.common import async_mock_service
|
||||
|
||||
|
||||
async def test_if_fires_on_hass_start(hass):
|
||||
|
@ -30,8 +31,7 @@ async def test_if_fires_on_hass_start(hass):
|
|||
assert len(calls) == 1
|
||||
|
||||
with patch(
|
||||
"homeassistant.config.async_hass_config_yaml",
|
||||
Mock(return_value=mock_coro(config)),
|
||||
"homeassistant.config.async_hass_config_yaml", AsyncMock(return_value=config),
|
||||
):
|
||||
await hass.services.async_call(
|
||||
automation.DOMAIN, automation.SERVICE_RELOAD, blocking=True
|
||||
|
|
|
@ -5,8 +5,6 @@ from datetime import timedelta
|
|||
import json
|
||||
import logging
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.awair.sensor import (
|
||||
ATTR_LAST_API_UPDATE,
|
||||
ATTR_TIMESTAMP,
|
||||
|
@ -29,6 +27,7 @@ from homeassistant.const import (
|
|||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import parse_datetime, utcnow
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed, load_fixture
|
||||
|
||||
DISCOVERY_CONFIG = {"sensor": {"platform": "awair", "access_token": "qwerty"}}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
"""Tests for the aws component config and setup."""
|
||||
from asynctest import CoroutineMock, MagicMock, patch as async_patch
|
||||
|
||||
from homeassistant.components import aws
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import AsyncMock, MagicMock, patch as async_patch
|
||||
|
||||
|
||||
class MockAioSession:
|
||||
"""Mock AioSession."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Init a mock session."""
|
||||
self.get_user = CoroutineMock()
|
||||
self.invoke = CoroutineMock()
|
||||
self.publish = CoroutineMock()
|
||||
self.send_message = CoroutineMock()
|
||||
self.get_user = AsyncMock()
|
||||
self.invoke = AsyncMock()
|
||||
self.publish = AsyncMock()
|
||||
self.send_message = AsyncMock()
|
||||
|
||||
def create_client(self, *args, **kwargs): # pylint: disable=no-self-use
|
||||
"""Create a mocked client."""
|
||||
return MagicMock(
|
||||
__aenter__=CoroutineMock(
|
||||
return_value=CoroutineMock(
|
||||
__aenter__=AsyncMock(
|
||||
return_value=AsyncMock(
|
||||
get_user=self.get_user, # iam
|
||||
invoke=self.invoke, # lambda
|
||||
publish=self.publish, # sns
|
||||
send_message=self.send_message, # sqs
|
||||
)
|
||||
),
|
||||
__aexit__=CoroutineMock(),
|
||||
__aexit__=AsyncMock(),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
"""Test Axis config flow."""
|
||||
from asynctest import Mock, patch
|
||||
|
||||
from homeassistant.components import axis
|
||||
from homeassistant.components.axis import config_flow
|
||||
|
||||
from .test_device import MAC, MODEL, NAME, setup_axis_integration
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
"""Test Axis device."""
|
||||
from copy import deepcopy
|
||||
|
||||
from asynctest import Mock, patch
|
||||
import axis as axislib
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import axis
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
MAC = "00408C12345"
|
||||
|
|
|
@ -6,7 +6,8 @@ from homeassistant.setup import async_setup_component
|
|||
|
||||
from .test_device import MAC, setup_axis_integration
|
||||
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
from tests.async_mock import AsyncMock
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_setup_no_config(hass):
|
||||
|
@ -30,7 +31,7 @@ async def test_setup_entry_fails(hass):
|
|||
config_entry.add_to_hass(hass)
|
||||
|
||||
mock_device = Mock()
|
||||
mock_device.async_setup.return_value = mock_coro(False)
|
||||
mock_device.async_setup = AsyncMock(return_value=False)
|
||||
|
||||
with patch.object(axis, "AxisNetworkDevice") as mock_device_class:
|
||||
mock_device_class.return_value = mock_device
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
"""Define tests for the Bravia TV config flow."""
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.braviatv.const import CONF_IGNORED_SOURCES, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PIN
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
BRAVIA_SYSTEM_INFO = {
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
"""Tests for Brother Printer integration."""
|
||||
import json
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.brother.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_TYPE
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Define tests for the Brother Printer config flow."""
|
||||
import json
|
||||
|
||||
from asynctest import patch
|
||||
from brother import SnmpError, UnsupportedModel
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
|
@ -9,6 +8,7 @@ from homeassistant.components.brother.const import DOMAIN
|
|||
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
||||
from homeassistant.const import CONF_HOST, CONF_TYPE
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
CONFIG = {CONF_HOST: "localhost", CONF_TYPE: "laser"}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""Test init of Brother integration."""
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.brother.const import DOMAIN
|
||||
from homeassistant.config_entries import (
|
||||
ENTRY_STATE_LOADED,
|
||||
|
@ -9,6 +7,7 @@ from homeassistant.config_entries import (
|
|||
)
|
||||
from homeassistant.const import CONF_HOST, CONF_TYPE, STATE_UNAVAILABLE
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.brother import init_integration
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
from datetime import timedelta
|
||||
import json
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.brother.const import UNIT_PAGES
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
|
@ -16,6 +14,7 @@ from homeassistant.const import (
|
|||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed, load_fixture
|
||||
from tests.components.brother import init_integration
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import datetime
|
||||
from unittest.mock import MagicMock, Mock
|
||||
|
||||
from asynctest import patch
|
||||
from caldav.objects import Event
|
||||
import pytest
|
||||
|
||||
|
@ -10,6 +9,8 @@ from homeassistant.const import STATE_OFF, STATE_ON
|
|||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
# pylint: disable=redefined-outer-name
|
||||
|
||||
DEVICE_DATA = {"name": "Private Calendar", "device_id": "Private Calendar"}
|
||||
|
|
|
@ -4,7 +4,6 @@ import base64
|
|||
import io
|
||||
from unittest.mock import PropertyMock, mock_open
|
||||
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import camera
|
||||
|
@ -15,6 +14,7 @@ from homeassistant.const import ATTR_ENTITY_ID, EVENT_HOMEASSISTANT_START
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.components.camera import common
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
from typing import Optional
|
||||
from uuid import UUID
|
||||
|
||||
from asynctest import MagicMock, Mock, patch
|
||||
import attr
|
||||
import pytest
|
||||
|
||||
|
@ -14,6 +13,7 @@ from homeassistant.exceptions import PlatformNotReady
|
|||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import MagicMock, Mock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
import socket
|
||||
import ssl
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.cert_expiry.const import DEFAULT_PORT, DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
|
||||
|
||||
from .const import HOST, PORT
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""Tests for Cert Expiry setup."""
|
||||
from datetime import timedelta
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.cert_expiry.const import DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED
|
||||
|
@ -12,6 +10,7 @@ import homeassistant.util.dt as dt_util
|
|||
|
||||
from .const import HOST, PORT
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
|
|
|
@ -3,13 +3,12 @@ from datetime import timedelta
|
|||
import socket
|
||||
import ssl
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT, STATE_UNAVAILABLE
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .const import HOST, PORT
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import asyncio
|
|||
import logging
|
||||
from time import time
|
||||
|
||||
from asynctest import CoroutineMock, Mock, patch
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
|
@ -11,6 +10,7 @@ from homeassistant.components.cloud import account_link
|
|||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.async_mock import AsyncMock, Mock, patch
|
||||
from tests.common import async_fire_time_changed, mock_platform
|
||||
|
||||
TEST_DOMAIN = "oauth2_test"
|
||||
|
@ -109,7 +109,7 @@ async def test_implementation(hass, flow_handler):
|
|||
flow_finished = asyncio.Future()
|
||||
|
||||
helper = Mock(
|
||||
async_get_authorize_url=CoroutineMock(return_value="http://example.com/auth"),
|
||||
async_get_authorize_url=AsyncMock(return_value="http://example.com/auth"),
|
||||
async_get_tokens=Mock(return_value=flow_finished),
|
||||
)
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
"""Test Alexa config."""
|
||||
import contextlib
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from homeassistant.components.cloud import ALEXA_SCHEMA, alexa_config
|
||||
from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.common import async_fire_time_changed, mock_coro
|
||||
from tests.async_mock import AsyncMock, Mock, patch
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
||||
async def test_alexa_config_expose_entity_prefs(hass, cloud_prefs):
|
||||
|
@ -28,7 +28,7 @@ async def test_alexa_config_report_state(hass, cloud_prefs):
|
|||
assert conf.should_report_state is False
|
||||
assert conf.is_reporting_states is False
|
||||
|
||||
with patch.object(conf, "async_get_access_token", return_value=mock_coro("hello")):
|
||||
with patch.object(conf, "async_get_access_token", AsyncMock(return_value="hello")):
|
||||
await cloud_prefs.async_update(alexa_report_state=True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -60,7 +60,7 @@ async def test_alexa_config_invalidate_token(hass, cloud_prefs, aioclient_mock):
|
|||
cloud_prefs,
|
||||
Mock(
|
||||
alexa_access_token_url="http://example/alexa_token",
|
||||
auth=Mock(async_check_token=Mock(side_effect=mock_coro)),
|
||||
auth=Mock(async_check_token=AsyncMock()),
|
||||
websession=hass.helpers.aiohttp_client.async_get_clientsession(),
|
||||
),
|
||||
)
|
||||
|
@ -189,13 +189,9 @@ async def test_alexa_update_report_state(hass, cloud_prefs):
|
|||
alexa_config.AlexaConfig(hass, ALEXA_SCHEMA({}), cloud_prefs, None)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.cloud.alexa_config.AlexaConfig."
|
||||
"async_sync_entities",
|
||||
side_effect=mock_coro,
|
||||
"homeassistant.components.cloud.alexa_config.AlexaConfig.async_sync_entities",
|
||||
) as mock_sync, patch(
|
||||
"homeassistant.components.cloud.alexa_config."
|
||||
"AlexaConfig.async_enable_proactive_mode",
|
||||
side_effect=mock_coro,
|
||||
"homeassistant.components.cloud.alexa_config.AlexaConfig.async_enable_proactive_mode",
|
||||
):
|
||||
await cloud_prefs.async_update(alexa_report_state=True)
|
||||
await hass.async_block_till_done()
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
"""Tests for the cloud binary sensor."""
|
||||
from unittest.mock import Mock
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.cloud.const import DISPATCHER_REMOTE_UPDATE
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
async def test_remote_connection_sensor(hass):
|
||||
"""Test the remote connection sensor."""
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.setup import async_setup_component
|
|||
|
||||
from . import mock_cloud, mock_cloud_prefs
|
||||
|
||||
from tests.async_mock import AsyncMock
|
||||
from tests.common import mock_coro
|
||||
from tests.components.alexa import test_smart_home as test_alexa
|
||||
|
||||
|
@ -221,7 +222,7 @@ async def test_set_username(hass):
|
|||
prefs = MagicMock(
|
||||
alexa_enabled=False,
|
||||
google_enabled=False,
|
||||
async_set_username=MagicMock(return_value=mock_coro()),
|
||||
async_set_username=AsyncMock(return_value=None),
|
||||
)
|
||||
client = CloudClient(hass, prefs, None, {}, {})
|
||||
client.cloud = MagicMock(is_logged_in=True, username="mock-username")
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""Test the Cloud Google Config."""
|
||||
from unittest.mock import Mock
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.cloud import GACTIONS_SCHEMA
|
||||
from homeassistant.components.cloud.google_config import CloudGoogleConfig
|
||||
from homeassistant.components.google_assistant import helpers as ga_helpers
|
||||
|
@ -11,7 +9,8 @@ from homeassistant.core import CoreState
|
|||
from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.common import async_fire_time_changed, mock_coro
|
||||
from tests.async_mock import AsyncMock, patch
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
||||
async def test_google_update_report_state(hass, cloud_prefs):
|
||||
|
@ -43,12 +42,12 @@ async def test_sync_entities(aioclient_mock, hass, cloud_prefs):
|
|||
GACTIONS_SCHEMA({}),
|
||||
"mock-user-id",
|
||||
cloud_prefs,
|
||||
Mock(auth=Mock(async_check_token=Mock(side_effect=mock_coro))),
|
||||
Mock(auth=Mock(async_check_token=AsyncMock())),
|
||||
)
|
||||
|
||||
with patch(
|
||||
"hass_nabucasa.cloud_api.async_google_actions_request_sync",
|
||||
return_value=mock_coro(Mock(status=HTTP_NOT_FOUND)),
|
||||
return_value=Mock(status=HTTP_NOT_FOUND),
|
||||
) as mock_request_sync:
|
||||
assert await config.async_sync_entities("user") == HTTP_NOT_FOUND
|
||||
assert len(mock_request_sync.mock_calls) == 1
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
"""Tests for the HTTP API for the cloud component."""
|
||||
import asyncio
|
||||
from ipaddress import ip_network
|
||||
from unittest.mock import MagicMock, Mock
|
||||
|
||||
from asynctest import patch
|
||||
from hass_nabucasa import thingtalk
|
||||
from hass_nabucasa.auth import Unauthenticated, UnknownError
|
||||
from hass_nabucasa.const import STATE_CONNECTED
|
||||
|
@ -20,7 +18,7 @@ from homeassistant.core import State
|
|||
|
||||
from . import mock_cloud, mock_cloud_prefs
|
||||
|
||||
from tests.common import mock_coro
|
||||
from tests.async_mock import AsyncMock, MagicMock, Mock, patch
|
||||
from tests.components.google_assistant import MockConfig
|
||||
|
||||
SUBSCRIPTION_INFO_URL = "https://api-test.hass.io/subscription_info"
|
||||
|
@ -29,9 +27,7 @@ SUBSCRIPTION_INFO_URL = "https://api-test.hass.io/subscription_info"
|
|||
@pytest.fixture()
|
||||
def mock_auth():
|
||||
"""Mock check token."""
|
||||
with patch(
|
||||
"hass_nabucasa.auth.CognitoAuth.async_check_token", side_effect=mock_coro
|
||||
):
|
||||
with patch("hass_nabucasa.auth.CognitoAuth.async_check_token"):
|
||||
yield
|
||||
|
||||
|
||||
|
@ -89,7 +85,7 @@ async def test_google_actions_sync(mock_cognito, mock_cloud_login, cloud_client)
|
|||
"""Test syncing Google Actions."""
|
||||
with patch(
|
||||
"hass_nabucasa.cloud_api.async_google_actions_request_sync",
|
||||
return_value=mock_coro(Mock(status=200)),
|
||||
return_value=Mock(status=200),
|
||||
) as mock_request_sync:
|
||||
req = await cloud_client.post("/api/cloud/google_actions/sync")
|
||||
assert req.status == 200
|
||||
|
@ -100,7 +96,7 @@ async def test_google_actions_sync_fails(mock_cognito, mock_cloud_login, cloud_c
|
|||
"""Test syncing Google Actions gone bad."""
|
||||
with patch(
|
||||
"hass_nabucasa.cloud_api.async_google_actions_request_sync",
|
||||
return_value=mock_coro(Mock(status=HTTP_INTERNAL_SERVER_ERROR)),
|
||||
return_value=Mock(status=HTTP_INTERNAL_SERVER_ERROR),
|
||||
) as mock_request_sync:
|
||||
req = await cloud_client.post("/api/cloud/google_actions/sync")
|
||||
assert req.status == HTTP_INTERNAL_SERVER_ERROR
|
||||
|
@ -109,7 +105,7 @@ async def test_google_actions_sync_fails(mock_cognito, mock_cloud_login, cloud_c
|
|||
|
||||
async def test_login_view(hass, cloud_client):
|
||||
"""Test logging in."""
|
||||
hass.data["cloud"] = MagicMock(login=MagicMock(return_value=mock_coro()))
|
||||
hass.data["cloud"] = MagicMock(login=AsyncMock())
|
||||
|
||||
req = await cloud_client.post(
|
||||
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
|
||||
|
@ -184,7 +180,7 @@ async def test_login_view_unknown_error(cloud_client):
|
|||
async def test_logout_view(hass, cloud_client):
|
||||
"""Test logging out."""
|
||||
cloud = hass.data["cloud"] = MagicMock()
|
||||
cloud.logout.return_value = mock_coro()
|
||||
cloud.logout = AsyncMock(return_value=None)
|
||||
req = await cloud_client.post("/api/cloud/logout")
|
||||
assert req.status == 200
|
||||
data = await req.json()
|
||||
|
@ -450,8 +446,7 @@ async def test_websocket_subscription_not_logged_in(hass, hass_ws_client):
|
|||
"""Test querying the status."""
|
||||
client = await hass_ws_client(hass)
|
||||
with patch(
|
||||
"hass_nabucasa.Cloud.fetch_subscription_info",
|
||||
return_value=mock_coro({"return": "value"}),
|
||||
"hass_nabucasa.Cloud.fetch_subscription_info", return_value={"return": "value"},
|
||||
):
|
||||
await client.send_json({"id": 5, "type": "cloud/subscription"})
|
||||
response = await client.receive_json()
|
||||
|
@ -529,7 +524,7 @@ async def test_enabling_webhook(hass, hass_ws_client, setup_api, mock_cloud_logi
|
|||
"""Test we call right code to enable webhooks."""
|
||||
client = await hass_ws_client(hass)
|
||||
with patch(
|
||||
"hass_nabucasa.cloudhooks.Cloudhooks.async_create", return_value=mock_coro()
|
||||
"hass_nabucasa.cloudhooks.Cloudhooks.async_create", return_value={}
|
||||
) as mock_enable:
|
||||
await client.send_json(
|
||||
{"id": 5, "type": "cloud/cloudhook/create", "webhook_id": "mock-webhook-id"}
|
||||
|
@ -544,9 +539,7 @@ async def test_enabling_webhook(hass, hass_ws_client, setup_api, mock_cloud_logi
|
|||
async def test_disabling_webhook(hass, hass_ws_client, setup_api, mock_cloud_login):
|
||||
"""Test we call right code to disable webhooks."""
|
||||
client = await hass_ws_client(hass)
|
||||
with patch(
|
||||
"hass_nabucasa.cloudhooks.Cloudhooks.async_delete", return_value=mock_coro()
|
||||
) as mock_disable:
|
||||
with patch("hass_nabucasa.cloudhooks.Cloudhooks.async_delete") as mock_disable:
|
||||
await client.send_json(
|
||||
{"id": 5, "type": "cloud/cloudhook/delete", "webhook_id": "mock-webhook-id"}
|
||||
)
|
||||
|
@ -562,9 +555,7 @@ async def test_enabling_remote(hass, hass_ws_client, setup_api, mock_cloud_login
|
|||
client = await hass_ws_client(hass)
|
||||
cloud = hass.data[DOMAIN]
|
||||
|
||||
with patch(
|
||||
"hass_nabucasa.remote.RemoteUI.connect", return_value=mock_coro()
|
||||
) as mock_connect:
|
||||
with patch("hass_nabucasa.remote.RemoteUI.connect") as mock_connect:
|
||||
await client.send_json({"id": 5, "type": "cloud/remote/connect"})
|
||||
response = await client.receive_json()
|
||||
assert response["success"]
|
||||
|
@ -578,9 +569,7 @@ async def test_disabling_remote(hass, hass_ws_client, setup_api, mock_cloud_logi
|
|||
client = await hass_ws_client(hass)
|
||||
cloud = hass.data[DOMAIN]
|
||||
|
||||
with patch(
|
||||
"hass_nabucasa.remote.RemoteUI.disconnect", return_value=mock_coro()
|
||||
) as mock_disconnect:
|
||||
with patch("hass_nabucasa.remote.RemoteUI.disconnect") as mock_disconnect:
|
||||
await client.send_json({"id": 5, "type": "cloud/remote/disconnect"})
|
||||
response = await client.receive_json()
|
||||
assert response["success"]
|
||||
|
@ -670,9 +659,7 @@ async def test_enabling_remote_trusted_networks_other(
|
|||
client = await hass_ws_client(hass)
|
||||
cloud = hass.data[DOMAIN]
|
||||
|
||||
with patch(
|
||||
"hass_nabucasa.remote.RemoteUI.connect", return_value=mock_coro()
|
||||
) as mock_connect:
|
||||
with patch("hass_nabucasa.remote.RemoteUI.connect") as mock_connect:
|
||||
await client.send_json({"id": 5, "type": "cloud/remote/connect"})
|
||||
response = await client.receive_json()
|
||||
|
||||
|
@ -885,7 +872,7 @@ async def test_thingtalk_convert(hass, hass_ws_client, setup_api):
|
|||
|
||||
with patch(
|
||||
"homeassistant.components.cloud.http_api.thingtalk.async_convert",
|
||||
return_value=mock_coro({"hello": "world"}),
|
||||
return_value={"hello": "world"},
|
||||
):
|
||||
await client.send_json(
|
||||
{"id": 5, "type": "cloud/thingtalk/convert", "query": "some-data"}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
"""Test Automation config panel."""
|
||||
import json
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components import config
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
async def test_get_device_config(hass, hass_client):
|
||||
"""Test getting device config."""
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Test hassbian config."""
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
|
@ -8,6 +7,8 @@ from homeassistant.components.websocket_api.const import TYPE_RESULT
|
|||
from homeassistant.const import CONF_UNIT_SYSTEM, CONF_UNIT_SYSTEM_IMPERIAL
|
||||
from homeassistant.util import dt as dt_util, location
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
ORIG_TIME_ZONE = dt_util.DEFAULT_TIME_ZONE
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
"""Test Customize config panel."""
|
||||
import json
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components import config
|
||||
from homeassistant.config import DATA_CUSTOMIZE
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
async def test_get_entity(hass, hass_client):
|
||||
"""Test getting entity."""
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from asynctest import CoroutineMock
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components import config
|
||||
|
||||
from tests.async_mock import AsyncMock
|
||||
|
||||
VIEW_NAME = "api:config:group:config"
|
||||
|
||||
|
||||
|
@ -52,7 +52,7 @@ async def test_update_device_config(hass, hass_client):
|
|||
"""Mock writing data."""
|
||||
written.append(data)
|
||||
|
||||
mock_call = CoroutineMock()
|
||||
mock_call = AsyncMock()
|
||||
|
||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||
"homeassistant.components.config._write", mock_write
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
"""Test config init."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components import config
|
||||
from homeassistant.const import EVENT_COMPONENT_LOADED
|
||||
from homeassistant.setup import ATTR_COMPONENT, async_setup_component
|
||||
|
||||
from tests.common import mock_component, mock_coro
|
||||
from tests.async_mock import patch
|
||||
from tests.common import mock_component
|
||||
|
||||
|
||||
async def test_config_setup(hass, loop):
|
||||
|
@ -20,8 +20,9 @@ async def test_load_on_demand_already_loaded(hass, aiohttp_client):
|
|||
|
||||
with patch.object(config, "SECTIONS", []), patch.object(
|
||||
config, "ON_DEMAND", ["zwave"]
|
||||
), patch("homeassistant.components.config.zwave.async_setup") as stp:
|
||||
stp.return_value = mock_coro(True)
|
||||
), patch(
|
||||
"homeassistant.components.config.zwave.async_setup", return_value=True
|
||||
) as stp:
|
||||
|
||||
await async_setup_component(hass, "config", {})
|
||||
|
||||
|
@ -38,8 +39,9 @@ async def test_load_on_demand_on_load(hass, aiohttp_client):
|
|||
|
||||
assert "config.zwave" not in hass.config.components
|
||||
|
||||
with patch("homeassistant.components.config.zwave.async_setup") as stp:
|
||||
stp.return_value = mock_coro(True)
|
||||
with patch(
|
||||
"homeassistant.components.config.zwave.async_setup", return_value=True
|
||||
) as stp:
|
||||
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: "zwave"})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
"""Test Automation config panel."""
|
||||
import json
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components import config
|
||||
from homeassistant.util.yaml import dump
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
async def test_update_scene(hass, hass_client):
|
||||
"""Test updating a scene."""
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
"""Fixtures for component testing."""
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def prevent_io():
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
"""Test the Coolmaster config flow."""
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.coolmaster.const import AVAILABLE_MODES, DOMAIN
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
def _flow_data():
|
||||
options = {"host": "1.1.1.1"}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
"""Test helpers."""
|
||||
|
||||
from asynctest import Mock, patch
|
||||
import pytest
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_cases():
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
"""deCONZ climate platform tests."""
|
||||
from copy import deepcopy
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components import deconz
|
||||
import homeassistant.components.climate as climate
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
SENSORS = {
|
||||
"1": {
|
||||
"id": "Thermostat id",
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
"""deCONZ cover platform tests."""
|
||||
from copy import deepcopy
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components import deconz
|
||||
import homeassistant.components.cover as cover
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
COVERS = {
|
||||
"1": {
|
||||
"id": "Level controllable cover id",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
"""Test deCONZ remote events."""
|
||||
from copy import deepcopy
|
||||
|
||||
from asynctest import Mock
|
||||
|
||||
from homeassistant.components.deconz.deconz_event import CONF_DECONZ_EVENT
|
||||
|
||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||
|
||||
from tests.common import async_capture_events
|
||||
|
||||
SENSORS = {
|
||||
"1": {
|
||||
"id": "Switch 1 id",
|
||||
|
@ -67,53 +67,40 @@ async def test_deconz_events(hass):
|
|||
switch_2_battery_level = hass.states.get("sensor.switch_2_battery_level")
|
||||
assert switch_2_battery_level.state == "100"
|
||||
|
||||
mock_listener = Mock()
|
||||
unsub = hass.bus.async_listen(CONF_DECONZ_EVENT, mock_listener)
|
||||
events = async_capture_events(hass, CONF_DECONZ_EVENT)
|
||||
|
||||
gateway.api.sensors["1"].update({"state": {"buttonevent": 2000}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_listener.mock_calls) == 1
|
||||
assert mock_listener.mock_calls[0][1][0].data == {
|
||||
assert len(events) == 1
|
||||
assert events[0].data == {
|
||||
"id": "switch_1",
|
||||
"unique_id": "00:00:00:00:00:00:00:01",
|
||||
"event": 2000,
|
||||
}
|
||||
|
||||
unsub()
|
||||
|
||||
mock_listener = Mock()
|
||||
unsub = hass.bus.async_listen(CONF_DECONZ_EVENT, mock_listener)
|
||||
|
||||
gateway.api.sensors["3"].update({"state": {"buttonevent": 2000}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_listener.mock_calls) == 1
|
||||
assert mock_listener.mock_calls[0][1][0].data == {
|
||||
assert len(events) == 2
|
||||
assert events[1].data == {
|
||||
"id": "switch_3",
|
||||
"unique_id": "00:00:00:00:00:00:00:03",
|
||||
"event": 2000,
|
||||
"gesture": 1,
|
||||
}
|
||||
|
||||
unsub()
|
||||
|
||||
mock_listener = Mock()
|
||||
unsub = hass.bus.async_listen(CONF_DECONZ_EVENT, mock_listener)
|
||||
|
||||
gateway.api.sensors["4"].update({"state": {"gesture": 0}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_listener.mock_calls) == 1
|
||||
assert mock_listener.mock_calls[0][1][0].data == {
|
||||
assert len(events) == 3
|
||||
assert events[2].data == {
|
||||
"id": "switch_4",
|
||||
"unique_id": "00:00:00:00:00:00:00:04",
|
||||
"event": 1000,
|
||||
"gesture": 0,
|
||||
}
|
||||
|
||||
unsub()
|
||||
|
||||
await gateway.async_reset()
|
||||
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Test deCONZ gateway."""
|
||||
from copy import deepcopy
|
||||
|
||||
from asynctest import Mock, patch
|
||||
import pydeconz
|
||||
import pytest
|
||||
|
||||
|
@ -9,6 +8,7 @@ from homeassistant import config_entries
|
|||
from homeassistant.components import deconz, ssdp
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
API_KEY = "1234567890ABCDEF"
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
import asyncio
|
||||
from copy import deepcopy
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components import deconz
|
||||
|
||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
ENTRY1_HOST = "1.2.3.4"
|
||||
ENTRY1_PORT = 80
|
||||
ENTRY1_API_KEY = "1234567890ABCDEF"
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
"""deCONZ light platform tests."""
|
||||
from copy import deepcopy
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components import deconz
|
||||
import homeassistant.components.light as light
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
GROUPS = {
|
||||
"1": {
|
||||
"id": "Light group id",
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
"""deCONZ scene platform tests."""
|
||||
from copy import deepcopy
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components import deconz
|
||||
import homeassistant.components.scene as scene
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
GROUPS = {
|
||||
"1": {
|
||||
"id": "Light group id",
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""deCONZ service tests."""
|
||||
|
||||
from asynctest import Mock, patch
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -9,6 +8,8 @@ from homeassistant.components.deconz.const import CONF_BRIDGE_ID
|
|||
|
||||
from .test_gateway import BRIDGEID, setup_deconz_integration
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
|
||||
GROUP = {
|
||||
"1": {
|
||||
"id": "Group 1 id",
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
"""deCONZ switch platform tests."""
|
||||
from copy import deepcopy
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components import deconz
|
||||
import homeassistant.components.switch as switch
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
SWITCHES = {
|
||||
"1": {
|
||||
"id": "On off switch id",
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The tests for the Demo Media player platform."""
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -7,6 +6,7 @@ import homeassistant.components.media_player as mp
|
|||
from homeassistant.helpers.aiohttp_client import DATA_CLIENTSESSION
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.components.media_player import common
|
||||
|
||||
TEST_ENTITY_ID = "media_player.walkman"
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
# pylint: disable=protected-access
|
||||
from datetime import datetime
|
||||
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import (
|
||||
|
@ -23,6 +22,7 @@ from homeassistant.const import (
|
|||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import json
|
|||
import logging
|
||||
import os
|
||||
|
||||
from asynctest import Mock, call, patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import zone
|
||||
|
@ -28,6 +27,7 @@ from homeassistant.helpers.json import JSONEncoder
|
|||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.async_mock import Mock, call, patch
|
||||
from tests.common import (
|
||||
assert_setup_component,
|
||||
async_fire_time_changed,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""Test the DirecTV config flow."""
|
||||
from aiohttp import ClientError as HTTPClientError
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.directv.const import CONF_RECEIVER_ID, DOMAIN
|
||||
from homeassistant.components.ssdp import ATTR_UPNP_SERIAL
|
||||
|
@ -13,6 +12,7 @@ from homeassistant.data_entry_flow import (
|
|||
)
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.components.directv import (
|
||||
HOST,
|
||||
MOCK_SSDP_DISCOVERY_INFO,
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from datetime import datetime, timedelta
|
||||
from typing import Optional
|
||||
|
||||
from asynctest import patch
|
||||
from pytest import fixture
|
||||
|
||||
from homeassistant.components.directv.media_player import (
|
||||
|
@ -55,6 +54,7 @@ from homeassistant.const import (
|
|||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.components.directv import setup_integration
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""The tests for the DirecTV remote platform."""
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.remote import (
|
||||
ATTR_COMMAND,
|
||||
DOMAIN as REMOTE_DOMAIN,
|
||||
|
@ -9,6 +7,7 @@ from homeassistant.components.remote import (
|
|||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.components.directv import setup_integration
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""The tests for the discovery component."""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
|
@ -9,6 +8,7 @@ from homeassistant.bootstrap import async_setup_component
|
|||
from homeassistant.components import discovery
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed, mock_coro
|
||||
|
||||
# One might consider to "mock" services, but it's easy enough to just use
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
"""Test the DoorBird config flow."""
|
||||
import urllib
|
||||
|
||||
from asynctest import MagicMock, patch
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow, setup
|
||||
from homeassistant.components.doorbird import CONF_CUSTOM_URL, CONF_TOKEN
|
||||
from homeassistant.components.doorbird.const import CONF_EVENTS, DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME
|
||||
|
||||
from tests.async_mock import MagicMock, patch
|
||||
from tests.common import MockConfigEntry, init_recorder_component
|
||||
|
||||
VALID_CONFIG = {
|
||||
|
|
|
@ -11,13 +11,13 @@ from decimal import Decimal
|
|||
from itertools import chain, repeat
|
||||
from unittest.mock import DEFAULT, Mock
|
||||
|
||||
import asynctest
|
||||
import pytest
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.dsmr.sensor import DerivativeDSMREntity
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR, TIME_HOURS, VOLUME_CUBIC_METERS
|
||||
|
||||
import tests.async_mock
|
||||
from tests.common import assert_setup_component
|
||||
|
||||
|
||||
|
@ -26,8 +26,8 @@ def mock_connection_factory(monkeypatch):
|
|||
"""Mock the create functions for serial and TCP Asyncio connections."""
|
||||
from dsmr_parser.clients.protocol import DSMRProtocol
|
||||
|
||||
transport = asynctest.Mock(spec=asyncio.Transport)
|
||||
protocol = asynctest.Mock(spec=DSMRProtocol)
|
||||
transport = tests.async_mock.Mock(spec=asyncio.Transport)
|
||||
protocol = tests.async_mock.Mock(spec=DSMRProtocol)
|
||||
|
||||
async def connection_factory(*args, **kwargs):
|
||||
"""Return mocked out Asyncio classes."""
|
||||
|
@ -327,7 +327,7 @@ async def test_connection_errors_retry(hass, monkeypatch, mock_connection_factor
|
|||
config = {"platform": "dsmr", "reconnect_interval": 0}
|
||||
|
||||
# override the mock to have it fail the first time and succeed after
|
||||
first_fail_connection_factory = asynctest.CoroutineMock(
|
||||
first_fail_connection_factory = tests.async_mock.AsyncMock(
|
||||
return_value=(transport, protocol),
|
||||
side_effect=chain([TimeoutError], repeat(DEFAULT)),
|
||||
)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
"""Common functions for tests."""
|
||||
from asynctest import CoroutineMock, Mock, call, patch
|
||||
|
||||
from homeassistant.components import dynalite
|
||||
from homeassistant.helpers import entity_registry
|
||||
|
||||
from tests.async_mock import AsyncMock, Mock, call, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
ATTR_SERVICE = "service"
|
||||
|
@ -38,7 +37,7 @@ async def create_entity_from_device(hass, device):
|
|||
with patch(
|
||||
"homeassistant.components.dynalite.bridge.DynaliteDevices"
|
||||
) as mock_dyn_dev:
|
||||
mock_dyn_dev().async_setup = CoroutineMock(return_value=True)
|
||||
mock_dyn_dev().async_setup = AsyncMock(return_value=True)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
new_device_func = mock_dyn_dev.mock_calls[1][2]["new_device_func"]
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
"""Test Dynalite bridge."""
|
||||
|
||||
from asynctest import CoroutineMock, Mock, patch
|
||||
|
||||
from homeassistant.components import dynalite
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from tests.async_mock import AsyncMock, Mock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
|
@ -16,7 +15,7 @@ async def test_update_device(hass):
|
|||
with patch(
|
||||
"homeassistant.components.dynalite.bridge.DynaliteDevices"
|
||||
) as mock_dyn_dev:
|
||||
mock_dyn_dev().async_setup = CoroutineMock(return_value=True)
|
||||
mock_dyn_dev().async_setup = AsyncMock(return_value=True)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
# Not waiting so it add the devices before registration
|
||||
update_device_func = mock_dyn_dev.mock_calls[1][2]["update_device_func"]
|
||||
|
@ -46,7 +45,7 @@ async def test_add_devices_then_register(hass):
|
|||
with patch(
|
||||
"homeassistant.components.dynalite.bridge.DynaliteDevices"
|
||||
) as mock_dyn_dev:
|
||||
mock_dyn_dev().async_setup = CoroutineMock(return_value=True)
|
||||
mock_dyn_dev().async_setup = AsyncMock(return_value=True)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
# Not waiting so it add the devices before registration
|
||||
new_device_func = mock_dyn_dev.mock_calls[1][2]["new_device_func"]
|
||||
|
@ -79,7 +78,7 @@ async def test_register_then_add_devices(hass):
|
|||
with patch(
|
||||
"homeassistant.components.dynalite.bridge.DynaliteDevices"
|
||||
) as mock_dyn_dev:
|
||||
mock_dyn_dev().async_setup = CoroutineMock(return_value=True)
|
||||
mock_dyn_dev().async_setup = AsyncMock(return_value=True)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
new_device_func = mock_dyn_dev.mock_calls[1][2]["new_device_func"]
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
"""Test Dynalite config flow."""
|
||||
|
||||
from asynctest import CoroutineMock, patch
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import dynalite
|
||||
|
||||
from tests.async_mock import AsyncMock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
|
@ -69,7 +69,7 @@ async def test_existing_update(hass):
|
|||
with patch(
|
||||
"homeassistant.components.dynalite.bridge.DynaliteDevices"
|
||||
) as mock_dyn_dev:
|
||||
mock_dyn_dev().async_setup = CoroutineMock(return_value=True)
|
||||
mock_dyn_dev().async_setup = AsyncMock(return_value=True)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
mock_dyn_dev().configure.assert_called_once()
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
"""Test Dynalite __init__."""
|
||||
|
||||
|
||||
from asynctest import call, patch
|
||||
|
||||
import homeassistant.components.dynalite.const as dynalite
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, CONF_ROOM
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import call, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import json
|
||||
from unittest import mock
|
||||
|
||||
import asynctest
|
||||
from libpurecool.dyson_pure_cool import DysonPureCool
|
||||
from libpurecool.dyson_pure_state_v2 import DysonEnvironmentalSensorV2State
|
||||
|
||||
|
@ -19,6 +18,8 @@ from homeassistant.setup import async_setup_component
|
|||
|
||||
from .common import load_mock_device
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
def _get_dyson_purecool_device():
|
||||
"""Return a valid device as provided by the Dyson web services."""
|
||||
|
@ -46,8 +47,8 @@ def _get_config():
|
|||
}
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -65,8 +66,8 @@ async def test_purecool_aiq_attributes(devices, login, hass):
|
|||
assert attributes[dyson.ATTR_VOC] == 35
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -108,8 +109,8 @@ async def test_purecool_aiq_update_state(devices, login, hass):
|
|||
assert attributes[dyson.ATTR_VOC] == 55
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -124,8 +125,8 @@ async def test_purecool_component_setup_only_once(devices, login, hass):
|
|||
assert len(hass.data[dyson.DYSON_AIQ_DEVICES]) == 1
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -140,8 +141,8 @@ async def test_purecool_aiq_without_discovery(devices, login, hass):
|
|||
assert add_entities_mock.call_count == 0
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import asynctest
|
||||
from libpurecool.const import FocusMode, HeatMode, HeatState, HeatTarget
|
||||
from libpurecool.dyson_pure_hotcool_link import DysonPureHotCoolLink
|
||||
from libpurecool.dyson_pure_state import DysonPureHotCoolState
|
||||
|
@ -14,6 +13,7 @@ from homeassistant.setup import async_setup_component
|
|||
|
||||
from .common import load_mock_device
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
|
@ -344,11 +344,11 @@ class DysonTest(unittest.TestCase):
|
|||
assert entity.target_temperature == 23
|
||||
|
||||
|
||||
@asynctest.patch(
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_device_heat_on(), _get_device_cool()],
|
||||
)
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
async def test_setup_component_with_parent_discovery(
|
||||
mocked_login, mocked_devices, hass
|
||||
):
|
||||
|
|
|
@ -3,7 +3,6 @@ import json
|
|||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import asynctest
|
||||
from libpurecool.const import FanMode, FanSpeed, NightMode, Oscillation
|
||||
from libpurecool.dyson_pure_cool import DysonPureCool
|
||||
from libpurecool.dyson_pure_cool_link import DysonPureCoolLink
|
||||
|
@ -28,6 +27,7 @@ from homeassistant.setup import async_setup_component
|
|||
|
||||
from .common import load_mock_device
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
|
@ -386,8 +386,8 @@ class DysonTest(unittest.TestCase):
|
|||
dyson_device.set_night_mode.assert_called_with(True)
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecoollink_device()],
|
||||
)
|
||||
|
@ -404,8 +404,8 @@ async def test_purecoollink_attributes(devices, login, hass):
|
|||
assert attributes[ATTR_OSCILLATING] is True
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -426,8 +426,8 @@ async def test_purecool_turn_on(devices, login, hass):
|
|||
assert device.turn_on.call_count == 1
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -470,8 +470,8 @@ async def test_purecool_set_speed(devices, login, hass):
|
|||
device.set_fan_speed.assert_called_with(FanSpeed.FAN_SPEED_10)
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -492,8 +492,8 @@ async def test_purecool_turn_off(devices, login, hass):
|
|||
assert device.turn_off.call_count == 1
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -526,8 +526,8 @@ async def test_purecool_set_dyson_speed(devices, login, hass):
|
|||
device.set_fan_speed.assert_called_with(FanSpeed.FAN_SPEED_2)
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -562,8 +562,8 @@ async def test_purecool_oscillate(devices, login, hass):
|
|||
assert device.disable_oscillation.call_count == 1
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -599,8 +599,8 @@ async def test_purecool_set_night_mode(devices, login, hass):
|
|||
assert device.disable_night_mode.call_count == 1
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -635,8 +635,8 @@ async def test_purecool_set_auto_mode(devices, login, hass):
|
|||
assert device.disable_auto_mode.call_count == 1
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -671,8 +671,8 @@ async def test_purecool_set_angle(devices, login, hass):
|
|||
device.enable_oscillation.assert_called_with(90, 180)
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -707,8 +707,8 @@ async def test_purecool_set_flow_direction_front(devices, login, hass):
|
|||
assert device.disable_frontal_direction.call_count == 1
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -743,8 +743,8 @@ async def test_purecool_set_timer(devices, login, hass):
|
|||
assert device.disable_sleep_timer.call_count == 1
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -804,8 +804,8 @@ async def test_purecool_update_state(devices, login, hass):
|
|||
assert attributes[dyson.ATTR_DYSON_SPEED_LIST] == _get_supported_speeds()
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
@ -865,8 +865,8 @@ async def test_purecool_update_state_filter_inv(devices, login, hass):
|
|||
assert attributes[dyson.ATTR_DYSON_SPEED_LIST] == _get_supported_speeds()
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import asynctest
|
||||
from libpurecool.dyson_pure_cool import DysonPureCool
|
||||
from libpurecool.dyson_pure_cool_link import DysonPureCoolLink
|
||||
|
||||
|
@ -20,6 +19,7 @@ from homeassistant.setup import async_setup_component
|
|||
|
||||
from .common import load_mock_device
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
|
@ -258,8 +258,8 @@ class DysonTest(unittest.TestCase):
|
|||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
@patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Tests for the EE BrightBox device scanner."""
|
||||
from datetime import datetime
|
||||
|
||||
from asynctest import patch
|
||||
from eebrightbox import EEBrightBoxException
|
||||
import pytest
|
||||
|
||||
|
@ -9,6 +8,8 @@ from homeassistant.components.device_tracker import DOMAIN
|
|||
from homeassistant.const import CONF_PASSWORD, CONF_PLATFORM
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
def _configure_mock_get_devices(eebrightbox_mock):
|
||||
eebrightbox_instance = eebrightbox_mock.return_value
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
"""Test the Elk-M1 Control config flow."""
|
||||
|
||||
from asynctest import CoroutineMock, MagicMock, PropertyMock, patch
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.elkm1.const import DOMAIN
|
||||
|
||||
from tests.async_mock import AsyncMock, MagicMock, PropertyMock, patch
|
||||
|
||||
|
||||
def mock_elk(invalid_auth=None, sync_complete=None):
|
||||
"""Mock m1lib Elk."""
|
||||
mocked_elk = MagicMock()
|
||||
type(mocked_elk).invalid_auth = PropertyMock(return_value=invalid_auth)
|
||||
type(mocked_elk).sync_complete = CoroutineMock()
|
||||
type(mocked_elk).sync_complete = AsyncMock()
|
||||
return mocked_elk
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
"""Test config flow."""
|
||||
from collections import namedtuple
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.esphome import DATA_KEY, config_flow
|
||||
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
from tests.async_mock import AsyncMock, MagicMock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
MockDeviceInfo = namedtuple("DeviceInfo", ["uses_password", "name"])
|
||||
|
||||
|
@ -24,8 +24,8 @@ def mock_client():
|
|||
return mock_client
|
||||
|
||||
mock_client.side_effect = mock_constructor
|
||||
mock_client.connect.return_value = mock_coro()
|
||||
mock_client.disconnect.return_value = mock_coro()
|
||||
mock_client.connect = AsyncMock()
|
||||
mock_client.disconnect = AsyncMock()
|
||||
|
||||
yield mock_client
|
||||
|
||||
|
@ -53,7 +53,7 @@ async def test_user_connection_works(hass, mock_client):
|
|||
result = await flow.async_step_user(user_input=None)
|
||||
assert result["type"] == "form"
|
||||
|
||||
mock_client.device_info.return_value = mock_coro(MockDeviceInfo(False, "test"))
|
||||
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(False, "test"))
|
||||
|
||||
result = await flow.async_step_user(user_input={"host": "127.0.0.1", "port": 80})
|
||||
|
||||
|
@ -119,7 +119,7 @@ async def test_user_with_password(hass, mock_client):
|
|||
flow = _setup_flow_handler(hass)
|
||||
await flow.async_step_user(user_input=None)
|
||||
|
||||
mock_client.device_info.return_value = mock_coro(MockDeviceInfo(True, "test"))
|
||||
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(True, "test"))
|
||||
|
||||
result = await flow.async_step_user(user_input={"host": "127.0.0.1", "port": 6053})
|
||||
|
||||
|
@ -142,7 +142,7 @@ async def test_user_invalid_password(hass, mock_api_connection_error, mock_clien
|
|||
flow = _setup_flow_handler(hass)
|
||||
await flow.async_step_user(user_input=None)
|
||||
|
||||
mock_client.device_info.return_value = mock_coro(MockDeviceInfo(True, "test"))
|
||||
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(True, "test"))
|
||||
|
||||
await flow.async_step_user(user_input={"host": "127.0.0.1", "port": 6053})
|
||||
mock_client.connect.side_effect = mock_api_connection_error
|
||||
|
@ -163,7 +163,7 @@ async def test_discovery_initiation(hass, mock_client):
|
|||
"properties": {},
|
||||
}
|
||||
|
||||
mock_client.device_info.return_value = mock_coro(MockDeviceInfo(False, "test8266"))
|
||||
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(False, "test8266"))
|
||||
|
||||
result = await flow.async_step_zeroconf(user_input=service_info)
|
||||
assert result["type"] == "form"
|
||||
|
@ -245,7 +245,7 @@ async def test_discovery_duplicate_data(hass, mock_client):
|
|||
"properties": {"address": "test8266.local"},
|
||||
}
|
||||
|
||||
mock_client.device_info.return_value = mock_coro(MockDeviceInfo(False, "test8266"))
|
||||
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(False, "test8266"))
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome", data=service_info, context={"source": "zeroconf"}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
"""Test the flume config flow."""
|
||||
from asynctest import MagicMock, patch
|
||||
import requests.exceptions
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.flume.const import DOMAIN
|
||||
|
||||
from tests.async_mock import MagicMock, patch
|
||||
|
||||
|
||||
def _get_mocked_flume_device_list():
|
||||
flume_device_list_mock = MagicMock()
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Define tests for the flunearyou config flow."""
|
||||
from asynctest import patch
|
||||
from pyflunearyou.errors import FluNearYouError
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
|
@ -7,6 +6,7 @@ from homeassistant.components.flunearyou import DOMAIN
|
|||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The tests for the Flux switch platform."""
|
||||
from asynctest.mock import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import light, switch
|
||||
|
@ -14,6 +13,7 @@ from homeassistant.core import State
|
|||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import (
|
||||
assert_setup_component,
|
||||
async_fire_time_changed,
|
||||
|
|
|
@ -4,7 +4,6 @@ from aiofreepybox.exceptions import (
|
|||
HttpRequestError,
|
||||
InvalidTokenError,
|
||||
)
|
||||
from asynctest import CoroutineMock, patch
|
||||
import pytest
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
|
@ -12,6 +11,7 @@ from homeassistant.components.freebox.const import DOMAIN
|
|||
from homeassistant.config_entries import SOURCE_DISCOVERY, SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
|
||||
from tests.async_mock import AsyncMock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
HOST = "myrouter.freeboxos.fr"
|
||||
|
@ -22,17 +22,17 @@ PORT = 1234
|
|||
def mock_controller_connect():
|
||||
"""Mock a successful connection."""
|
||||
with patch("homeassistant.components.freebox.router.Freepybox") as service_mock:
|
||||
service_mock.return_value.open = CoroutineMock()
|
||||
service_mock.return_value.system.get_config = CoroutineMock(
|
||||
service_mock.return_value.open = AsyncMock()
|
||||
service_mock.return_value.system.get_config = AsyncMock(
|
||||
return_value={
|
||||
"mac": "abcd",
|
||||
"model_info": {"pretty_name": "Pretty Model"},
|
||||
"firmware_version": "123",
|
||||
}
|
||||
)
|
||||
service_mock.return_value.lan.get_hosts_list = CoroutineMock()
|
||||
service_mock.return_value.connection.get_status = CoroutineMock()
|
||||
service_mock.return_value.close = CoroutineMock()
|
||||
service_mock.return_value.lan.get_hosts_list = AsyncMock()
|
||||
service_mock.return_value.connection.get_status = AsyncMock()
|
||||
service_mock.return_value.close = AsyncMock()
|
||||
yield service_mock
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""The tests for Home Assistant frontend."""
|
||||
import re
|
||||
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.frontend import (
|
||||
|
@ -17,6 +16,7 @@ from homeassistant.const import HTTP_NOT_FOUND
|
|||
from homeassistant.loader import async_get_integration
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_capture_events
|
||||
|
||||
CONFIG_THEMES = {DOMAIN: {CONF_THEMES: {"happy": {"primary-color": "red"}}}}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Define tests for the GDACS config flow."""
|
||||
from datetime import timedelta
|
||||
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
|
@ -13,6 +12,8 @@ from homeassistant.const import (
|
|||
CONF_SCAN_INTERVAL,
|
||||
)
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
@pytest.fixture(name="gdacs_setup", autouse=True)
|
||||
def gdacs_setup_fixture():
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""The tests for the GDACS Feed integration."""
|
||||
import datetime
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components import gdacs
|
||||
from homeassistant.components.gdacs import DEFAULT_SCAN_INTERVAL, DOMAIN, FEED
|
||||
from homeassistant.components.gdacs.geo_location import (
|
||||
|
@ -35,6 +33,7 @@ from homeassistant.setup import async_setup_component
|
|||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.components.gdacs import _generate_mock_feed_entry
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
"""Define tests for the GDACS general setup."""
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.gdacs import DOMAIN, FEED
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
async def test_component_unload_config_entry(hass, config_entry):
|
||||
"""Test that loading and unloading of a config entry works."""
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""The tests for the GDACS Feed integration."""
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components import gdacs
|
||||
from homeassistant.components.gdacs import DEFAULT_SCAN_INTERVAL
|
||||
from homeassistant.components.gdacs.sensor import (
|
||||
|
@ -20,6 +18,7 @@ from homeassistant.const import (
|
|||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.components.gdacs import _generate_mock_feed_entry
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""The tests for the generic_thermostat."""
|
||||
import datetime
|
||||
|
||||
from asynctest import mock
|
||||
import pytest
|
||||
import pytz
|
||||
import voluptuous as vol
|
||||
|
@ -32,6 +31,7 @@ from homeassistant.core import DOMAIN as HASS_DOMAIN, CoreState, State, callback
|
|||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import assert_setup_component, mock_restore_cache
|
||||
from tests.components.climate import common
|
||||
|
||||
|
@ -622,7 +622,7 @@ async def test_temp_change_ac_trigger_on_long_enough(hass, setup_comp_4):
|
|||
fake_changed = datetime.datetime(
|
||||
1918, 11, 11, 11, 11, 11, tzinfo=datetime.timezone.utc
|
||||
)
|
||||
with mock.patch(
|
||||
with patch(
|
||||
"homeassistant.helpers.condition.dt_util.utcnow", return_value=fake_changed
|
||||
):
|
||||
calls = _setup_switch(hass, False)
|
||||
|
@ -650,7 +650,7 @@ async def test_temp_change_ac_trigger_off_long_enough(hass, setup_comp_4):
|
|||
fake_changed = datetime.datetime(
|
||||
1918, 11, 11, 11, 11, 11, tzinfo=datetime.timezone.utc
|
||||
)
|
||||
with mock.patch(
|
||||
with patch(
|
||||
"homeassistant.helpers.condition.dt_util.utcnow", return_value=fake_changed
|
||||
):
|
||||
calls = _setup_switch(hass, True)
|
||||
|
@ -733,7 +733,7 @@ async def test_temp_change_ac_trigger_on_long_enough_2(hass, setup_comp_5):
|
|||
fake_changed = datetime.datetime(
|
||||
1918, 11, 11, 11, 11, 11, tzinfo=datetime.timezone.utc
|
||||
)
|
||||
with mock.patch(
|
||||
with patch(
|
||||
"homeassistant.helpers.condition.dt_util.utcnow", return_value=fake_changed
|
||||
):
|
||||
calls = _setup_switch(hass, False)
|
||||
|
@ -761,7 +761,7 @@ async def test_temp_change_ac_trigger_off_long_enough_2(hass, setup_comp_5):
|
|||
fake_changed = datetime.datetime(
|
||||
1918, 11, 11, 11, 11, 11, tzinfo=datetime.timezone.utc
|
||||
)
|
||||
with mock.patch(
|
||||
with patch(
|
||||
"homeassistant.helpers.condition.dt_util.utcnow", return_value=fake_changed
|
||||
):
|
||||
calls = _setup_switch(hass, True)
|
||||
|
@ -852,7 +852,7 @@ async def test_temp_change_heater_trigger_on_long_enough(hass, setup_comp_6):
|
|||
fake_changed = datetime.datetime(
|
||||
1918, 11, 11, 11, 11, 11, tzinfo=datetime.timezone.utc
|
||||
)
|
||||
with mock.patch(
|
||||
with patch(
|
||||
"homeassistant.helpers.condition.dt_util.utcnow", return_value=fake_changed
|
||||
):
|
||||
calls = _setup_switch(hass, False)
|
||||
|
@ -871,7 +871,7 @@ async def test_temp_change_heater_trigger_off_long_enough(hass, setup_comp_6):
|
|||
fake_changed = datetime.datetime(
|
||||
1918, 11, 11, 11, 11, 11, tzinfo=datetime.timezone.utc
|
||||
)
|
||||
with mock.patch(
|
||||
with patch(
|
||||
"homeassistant.helpers.condition.dt_util.utcnow", return_value=fake_changed
|
||||
):
|
||||
calls = _setup_switch(hass, True)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue