Fix tests & lint
This commit is contained in:
parent
28e9f1d0b8
commit
dad11f8208
14 changed files with 112 additions and 87 deletions
|
@ -116,9 +116,9 @@ class MHZ19Sensor(Entity):
|
||||||
class MHZClient:
|
class MHZClient:
|
||||||
"""Get the latest data from the MH-Z sensor."""
|
"""Get the latest data from the MH-Z sensor."""
|
||||||
|
|
||||||
def __init__(self, co2sensor, serial):
|
def __init__(self, co2sens, serial):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.co2sensor = co2sensor
|
self.co2sensor = co2sens
|
||||||
self._serial = serial
|
self._serial = serial
|
||||||
self.data = dict()
|
self.data = dict()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""The tests for the ASUSWRT device tracker platform."""
|
"""The tests for the ASUSWRT device tracker platform."""
|
||||||
|
from unittest.mock import patch
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from homeassistant.components.asuswrt import (
|
from homeassistant.components.asuswrt import (
|
||||||
|
@ -10,7 +11,7 @@ from homeassistant.components.asuswrt import (
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_PLATFORM, CONF_PASSWORD, CONF_USERNAME, CONF_HOST
|
from homeassistant.const import CONF_PLATFORM, CONF_PASSWORD, CONF_USERNAME, CONF_HOST
|
||||||
|
|
||||||
from tests.common import MockDependency, mock_coro_func
|
from tests.common import mock_coro_func
|
||||||
|
|
||||||
FAKEFILE = None
|
FAKEFILE = None
|
||||||
|
|
||||||
|
@ -28,9 +29,9 @@ VALID_CONFIG_ROUTER_SSH = {
|
||||||
|
|
||||||
async def test_password_or_pub_key_required(hass):
|
async def test_password_or_pub_key_required(hass):
|
||||||
"""Test creating an AsusWRT scanner without a pass or pubkey."""
|
"""Test creating an AsusWRT scanner without a pass or pubkey."""
|
||||||
with MockDependency("aioasuswrt.asuswrt") as mocked_asus:
|
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
|
||||||
mocked_asus.AsusWrt().connection.async_connect = mock_coro_func()
|
AsusWrt().connection.async_connect = mock_coro_func()
|
||||||
mocked_asus.AsusWrt().is_connected = False
|
AsusWrt().is_connected = False
|
||||||
result = await async_setup_component(
|
result = await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}}
|
hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}}
|
||||||
)
|
)
|
||||||
|
@ -39,9 +40,9 @@ async def test_password_or_pub_key_required(hass):
|
||||||
|
|
||||||
async def test_get_scanner_with_password_no_pubkey(hass):
|
async def test_get_scanner_with_password_no_pubkey(hass):
|
||||||
"""Test creating an AsusWRT scanner with a password and no pubkey."""
|
"""Test creating an AsusWRT scanner with a password and no pubkey."""
|
||||||
with MockDependency("aioasuswrt.asuswrt") as mocked_asus:
|
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
|
||||||
mocked_asus.AsusWrt().connection.async_connect = mock_coro_func()
|
AsusWrt().connection.async_connect = mock_coro_func()
|
||||||
mocked_asus.AsusWrt().connection.async_get_connected_devices = mock_coro_func(
|
AsusWrt().connection.async_get_connected_devices = mock_coro_func(
|
||||||
return_value={}
|
return_value={}
|
||||||
)
|
)
|
||||||
result = await async_setup_component(
|
result = await async_setup_component(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# pylint: disable=redefined-outer-name
|
# pylint: disable=redefined-outer-name
|
||||||
"""Tests for the Daikin config flow."""
|
"""Tests for the Daikin config flow."""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ from homeassistant.components.daikin import config_flow
|
||||||
from homeassistant.components.daikin.const import KEY_IP, KEY_MAC
|
from homeassistant.components.daikin.const import KEY_IP, KEY_MAC
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, MockDependency
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
MAC = "AABBCCDDEEFF"
|
MAC = "AABBCCDDEEFF"
|
||||||
HOST = "127.0.0.1"
|
HOST = "127.0.0.1"
|
||||||
|
@ -30,10 +31,10 @@ def mock_daikin():
|
||||||
"""Mock the init function in pydaikin."""
|
"""Mock the init function in pydaikin."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with MockDependency("pydaikin.appliance") as mock_daikin_:
|
with patch("homeassistant.components.daikin.config_flow.Appliance") as Appliance:
|
||||||
mock_daikin_.Appliance().values.get.return_value = "AABBCCDDEEFF"
|
Appliance().values.get.return_value = "AABBCCDDEEFF"
|
||||||
mock_daikin_.Appliance().init = mock_daikin_init
|
Appliance().init = mock_daikin_init
|
||||||
yield mock_daikin_
|
yield Appliance
|
||||||
|
|
||||||
|
|
||||||
async def test_user(hass, mock_daikin):
|
async def test_user(hass, mock_daikin):
|
||||||
|
@ -94,7 +95,7 @@ async def test_discovery(hass, mock_daikin):
|
||||||
async def test_device_abort(hass, mock_daikin, s_effect, reason):
|
async def test_device_abort(hass, mock_daikin, s_effect, reason):
|
||||||
"""Test device abort."""
|
"""Test device abort."""
|
||||||
flow = init_config_flow(hass)
|
flow = init_config_flow(hass)
|
||||||
mock_daikin.Appliance.side_effect = s_effect
|
mock_daikin.side_effect = s_effect
|
||||||
|
|
||||||
result = await flow.async_step_user({CONF_HOST: HOST})
|
result = await flow.async_step_user({CONF_HOST: HOST})
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
|
|
|
@ -12,7 +12,7 @@ from homeassistant.setup import setup_component
|
||||||
import homeassistant.components.datadog as datadog
|
import homeassistant.components.datadog as datadog
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
|
|
||||||
from tests.common import assert_setup_component, get_test_home_assistant, MockDependency
|
from tests.common import assert_setup_component, get_test_home_assistant
|
||||||
|
|
||||||
|
|
||||||
class TestDatadog(unittest.TestCase):
|
class TestDatadog(unittest.TestCase):
|
||||||
|
@ -33,11 +33,11 @@ class TestDatadog(unittest.TestCase):
|
||||||
self.hass, datadog.DOMAIN, {datadog.DOMAIN: {"host1": "host1"}}
|
self.hass, datadog.DOMAIN, {datadog.DOMAIN: {"host1": "host1"}}
|
||||||
)
|
)
|
||||||
|
|
||||||
@MockDependency("datadog", "beer")
|
@mock.patch("homeassistant.components.datadog.statsd")
|
||||||
def test_datadog_setup_full(self, mock_datadog):
|
@mock.patch("homeassistant.components.datadog.initialize")
|
||||||
|
def test_datadog_setup_full(self, mock_connection, mock_client):
|
||||||
"""Test setup with all data."""
|
"""Test setup with all data."""
|
||||||
self.hass.bus.listen = mock.MagicMock()
|
self.hass.bus.listen = mock.MagicMock()
|
||||||
mock_connection = mock_datadog.initialize
|
|
||||||
|
|
||||||
assert setup_component(
|
assert setup_component(
|
||||||
self.hass,
|
self.hass,
|
||||||
|
@ -54,11 +54,11 @@ class TestDatadog(unittest.TestCase):
|
||||||
assert EVENT_LOGBOOK_ENTRY == self.hass.bus.listen.call_args_list[0][0][0]
|
assert EVENT_LOGBOOK_ENTRY == self.hass.bus.listen.call_args_list[0][0][0]
|
||||||
assert EVENT_STATE_CHANGED == self.hass.bus.listen.call_args_list[1][0][0]
|
assert EVENT_STATE_CHANGED == self.hass.bus.listen.call_args_list[1][0][0]
|
||||||
|
|
||||||
@MockDependency("datadog")
|
@mock.patch("homeassistant.components.datadog.statsd")
|
||||||
def test_datadog_setup_defaults(self, mock_datadog):
|
@mock.patch("homeassistant.components.datadog.initialize")
|
||||||
|
def test_datadog_setup_defaults(self, mock_connection, mock_client):
|
||||||
"""Test setup with defaults."""
|
"""Test setup with defaults."""
|
||||||
self.hass.bus.listen = mock.MagicMock()
|
self.hass.bus.listen = mock.MagicMock()
|
||||||
mock_connection = mock_datadog.initialize
|
|
||||||
|
|
||||||
assert setup_component(
|
assert setup_component(
|
||||||
self.hass,
|
self.hass,
|
||||||
|
@ -78,11 +78,11 @@ class TestDatadog(unittest.TestCase):
|
||||||
)
|
)
|
||||||
assert self.hass.bus.listen.called
|
assert self.hass.bus.listen.called
|
||||||
|
|
||||||
@MockDependency("datadog")
|
@mock.patch("homeassistant.components.datadog.statsd")
|
||||||
def test_logbook_entry(self, mock_datadog):
|
@mock.patch("homeassistant.components.datadog.initialize")
|
||||||
|
def test_logbook_entry(self, mock_connection, mock_client):
|
||||||
"""Test event listener."""
|
"""Test event listener."""
|
||||||
self.hass.bus.listen = mock.MagicMock()
|
self.hass.bus.listen = mock.MagicMock()
|
||||||
mock_client = mock_datadog.statsd
|
|
||||||
|
|
||||||
assert setup_component(
|
assert setup_component(
|
||||||
self.hass,
|
self.hass,
|
||||||
|
@ -110,11 +110,11 @@ class TestDatadog(unittest.TestCase):
|
||||||
|
|
||||||
mock_client.event.reset_mock()
|
mock_client.event.reset_mock()
|
||||||
|
|
||||||
@MockDependency("datadog")
|
@mock.patch("homeassistant.components.datadog.statsd")
|
||||||
def test_state_changed(self, mock_datadog):
|
@mock.patch("homeassistant.components.datadog.initialize")
|
||||||
|
def test_state_changed(self, mock_connection, mock_client):
|
||||||
"""Test event listener."""
|
"""Test event listener."""
|
||||||
self.hass.bus.listen = mock.MagicMock()
|
self.hass.bus.listen = mock.MagicMock()
|
||||||
mock_client = mock_datadog.statsd
|
|
||||||
|
|
||||||
assert setup_component(
|
assert setup_component(
|
||||||
self.hass,
|
self.hass,
|
||||||
|
|
|
@ -58,7 +58,7 @@ from homeassistant.helpers.discovery import async_load_platform
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from tests.common import MockDependency, async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
|
|
||||||
CLIENT_ENTITY_ID = "media_player.client_dvr"
|
CLIENT_ENTITY_ID = "media_player.client_dvr"
|
||||||
MAIN_ENTITY_ID = "media_player.main_dvr"
|
MAIN_ENTITY_ID = "media_player.main_dvr"
|
||||||
|
@ -179,8 +179,9 @@ def platforms(hass, dtv_side_effect, mock_now):
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
with MockDependency("DirectPy"), patch(
|
with patch(
|
||||||
"DirectPy.DIRECTV", side_effect=dtv_side_effect
|
"homeassistant.components.directv.media_player.DIRECTV",
|
||||||
|
side_effect=dtv_side_effect,
|
||||||
), patch("homeassistant.util.dt.utcnow", return_value=mock_now):
|
), patch("homeassistant.util.dt.utcnow", return_value=mock_now):
|
||||||
hass.loop.run_until_complete(async_setup_component(hass, DOMAIN, config))
|
hass.loop.run_until_complete(async_setup_component(hass, DOMAIN, config))
|
||||||
hass.loop.run_until_complete(hass.async_block_till_done())
|
hass.loop.run_until_complete(hass.async_block_till_done())
|
||||||
|
@ -309,7 +310,9 @@ class MockDirectvClass:
|
||||||
|
|
||||||
async def test_setup_platform_config(hass):
|
async def test_setup_platform_config(hass):
|
||||||
"""Test setting up the platform from configuration."""
|
"""Test setting up the platform from configuration."""
|
||||||
with MockDependency("DirectPy"), patch("DirectPy.DIRECTV", new=MockDirectvClass):
|
with patch(
|
||||||
|
"homeassistant.components.directv.media_player.DIRECTV", new=MockDirectvClass
|
||||||
|
):
|
||||||
|
|
||||||
await async_setup_component(hass, DOMAIN, WORKING_CONFIG)
|
await async_setup_component(hass, DOMAIN, WORKING_CONFIG)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -321,7 +324,9 @@ async def test_setup_platform_config(hass):
|
||||||
|
|
||||||
async def test_setup_platform_discover(hass):
|
async def test_setup_platform_discover(hass):
|
||||||
"""Test setting up the platform from discovery."""
|
"""Test setting up the platform from discovery."""
|
||||||
with MockDependency("DirectPy"), patch("DirectPy.DIRECTV", new=MockDirectvClass):
|
with patch(
|
||||||
|
"homeassistant.components.directv.media_player.DIRECTV", new=MockDirectvClass
|
||||||
|
):
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
async_load_platform(
|
async_load_platform(
|
||||||
|
@ -337,7 +342,9 @@ async def test_setup_platform_discover(hass):
|
||||||
|
|
||||||
async def test_setup_platform_discover_duplicate(hass):
|
async def test_setup_platform_discover_duplicate(hass):
|
||||||
"""Test setting up the platform from discovery."""
|
"""Test setting up the platform from discovery."""
|
||||||
with MockDependency("DirectPy"), patch("DirectPy.DIRECTV", new=MockDirectvClass):
|
with patch(
|
||||||
|
"homeassistant.components.directv.media_player.DIRECTV", new=MockDirectvClass
|
||||||
|
):
|
||||||
|
|
||||||
await async_setup_component(hass, DOMAIN, WORKING_CONFIG)
|
await async_setup_component(hass, DOMAIN, WORKING_CONFIG)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -358,7 +365,9 @@ async def test_setup_platform_discover_client(hass):
|
||||||
LOCATIONS.append({"locationName": "Client 1", "clientAddr": "1"})
|
LOCATIONS.append({"locationName": "Client 1", "clientAddr": "1"})
|
||||||
LOCATIONS.append({"locationName": "Client 2", "clientAddr": "2"})
|
LOCATIONS.append({"locationName": "Client 2", "clientAddr": "2"})
|
||||||
|
|
||||||
with MockDependency("DirectPy"), patch("DirectPy.DIRECTV", new=MockDirectvClass):
|
with patch(
|
||||||
|
"homeassistant.components.directv.media_player.DIRECTV", new=MockDirectvClass
|
||||||
|
):
|
||||||
|
|
||||||
await async_setup_component(hass, DOMAIN, WORKING_CONFIG)
|
await async_setup_component(hass, DOMAIN, WORKING_CONFIG)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
|
@ -44,7 +44,9 @@ async def test_events_fired_properly(hass):
|
||||||
def listener(event):
|
def listener(event):
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
with patch("emulated_roku.EmulatedRokuServer", instantiate):
|
with patch(
|
||||||
|
"homeassistant.components.emulated_roku.binding.EmulatedRokuServer", instantiate
|
||||||
|
):
|
||||||
hass.bus.async_listen(EVENT_ROKU_COMMAND, listener)
|
hass.bus.async_listen(EVENT_ROKU_COMMAND, listener)
|
||||||
|
|
||||||
assert await binding.setup() is True
|
assert await binding.setup() is True
|
||||||
|
|
|
@ -10,7 +10,7 @@ from tests.common import mock_coro_func
|
||||||
async def test_config_required_fields(hass):
|
async def test_config_required_fields(hass):
|
||||||
"""Test that configuration is successful with required fields."""
|
"""Test that configuration is successful with required fields."""
|
||||||
with patch.object(emulated_roku, "configured_servers", return_value=[]), patch(
|
with patch.object(emulated_roku, "configured_servers", return_value=[]), patch(
|
||||||
"emulated_roku.EmulatedRokuServer",
|
"homeassistant.components.emulated_roku.binding.EmulatedRokuServer",
|
||||||
return_value=Mock(start=mock_coro_func(), close=mock_coro_func()),
|
return_value=Mock(start=mock_coro_func(), close=mock_coro_func()),
|
||||||
):
|
):
|
||||||
assert (
|
assert (
|
||||||
|
@ -35,7 +35,7 @@ async def test_config_required_fields(hass):
|
||||||
async def test_config_already_registered_not_configured(hass):
|
async def test_config_already_registered_not_configured(hass):
|
||||||
"""Test that an already registered name causes the entry to be ignored."""
|
"""Test that an already registered name causes the entry to be ignored."""
|
||||||
with patch(
|
with patch(
|
||||||
"emulated_roku.EmulatedRokuServer",
|
"homeassistant.components.emulated_roku.binding.EmulatedRokuServer",
|
||||||
return_value=Mock(start=mock_coro_func(), close=mock_coro_func()),
|
return_value=Mock(start=mock_coro_func(), close=mock_coro_func()),
|
||||||
) as instantiate, patch.object(
|
) as instantiate, patch.object(
|
||||||
emulated_roku, "configured_servers", return_value=["Emulated Roku Test"]
|
emulated_roku, "configured_servers", return_value=["Emulated Roku Test"]
|
||||||
|
@ -74,7 +74,7 @@ async def test_setup_entry_successful(hass):
|
||||||
}
|
}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"emulated_roku.EmulatedRokuServer",
|
"homeassistant.components.emulated_roku.binding.EmulatedRokuServer",
|
||||||
return_value=Mock(start=mock_coro_func(), close=mock_coro_func()),
|
return_value=Mock(start=mock_coro_func(), close=mock_coro_func()),
|
||||||
) as instantiate:
|
) as instantiate:
|
||||||
assert await emulated_roku.async_setup_entry(hass, entry) is True
|
assert await emulated_roku.async_setup_entry(hass, entry) is True
|
||||||
|
@ -98,7 +98,7 @@ async def test_unload_entry(hass):
|
||||||
entry.data = {"name": "Emulated Roku Test", "listen_port": 8060}
|
entry.data = {"name": "Emulated Roku Test", "listen_port": 8060}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"emulated_roku.EmulatedRokuServer",
|
"homeassistant.components.emulated_roku.binding.EmulatedRokuServer",
|
||||||
return_value=Mock(start=mock_coro_func(), close=mock_coro_func()),
|
return_value=Mock(start=mock_coro_func(), close=mock_coro_func()),
|
||||||
):
|
):
|
||||||
assert await emulated_roku.async_setup_entry(hass, entry) is True
|
assert await emulated_roku.async_setup_entry(hass, entry) is True
|
||||||
|
|
|
@ -432,6 +432,8 @@ class TestLight(unittest.TestCase):
|
||||||
|
|
||||||
async def test_light_context(hass, hass_admin_user):
|
async def test_light_context(hass, hass_admin_user):
|
||||||
"""Test that light context works."""
|
"""Test that light context works."""
|
||||||
|
platform = getattr(hass.components, "test.light")
|
||||||
|
platform.init()
|
||||||
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
||||||
|
|
||||||
state = hass.states.get("light.ceiling")
|
state = hass.states.get("light.ceiling")
|
||||||
|
@ -453,6 +455,8 @@ async def test_light_context(hass, hass_admin_user):
|
||||||
|
|
||||||
async def test_light_turn_on_auth(hass, hass_admin_user):
|
async def test_light_turn_on_auth(hass, hass_admin_user):
|
||||||
"""Test that light context works."""
|
"""Test that light context works."""
|
||||||
|
platform = getattr(hass.components, "test.light")
|
||||||
|
platform.init()
|
||||||
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
||||||
|
|
||||||
state = hass.states.get("light.ceiling")
|
state = hass.states.get("light.ceiling")
|
||||||
|
|
|
@ -9,14 +9,11 @@ from homeassistant.components.logi_circle import config_flow
|
||||||
from homeassistant.components.logi_circle.config_flow import (
|
from homeassistant.components.logi_circle.config_flow import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
LogiCircleAuthCallbackView,
|
LogiCircleAuthCallbackView,
|
||||||
|
AuthorizationFailed,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockDependency, mock_coro
|
from tests.common import mock_coro
|
||||||
|
|
||||||
|
|
||||||
class AuthorizationFailed(Exception):
|
|
||||||
"""Dummy Exception."""
|
|
||||||
|
|
||||||
|
|
||||||
class MockRequest:
|
class MockRequest:
|
||||||
|
@ -50,19 +47,15 @@ def init_config_flow(hass):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_logi_circle():
|
def mock_logi_circle():
|
||||||
"""Mock logi_circle."""
|
"""Mock logi_circle."""
|
||||||
with MockDependency("logi_circle", "exception") as mock_logi_circle_:
|
with patch(
|
||||||
mock_logi_circle_.exception.AuthorizationFailed = AuthorizationFailed
|
"homeassistant.components.logi_circle.config_flow.LogiCircle"
|
||||||
mock_logi_circle_.LogiCircle().authorize = Mock(
|
) as logi_circle:
|
||||||
return_value=mock_coro(return_value=True)
|
LogiCircle = logi_circle()
|
||||||
)
|
LogiCircle.authorize = Mock(return_value=mock_coro(return_value=True))
|
||||||
mock_logi_circle_.LogiCircle().close = Mock(
|
LogiCircle.close = Mock(return_value=mock_coro(return_value=True))
|
||||||
return_value=mock_coro(return_value=True)
|
LogiCircle.account = mock_coro(return_value={"accountId": "testId"})
|
||||||
)
|
LogiCircle.authorize_url = "http://authorize.url"
|
||||||
mock_logi_circle_.LogiCircle().account = mock_coro(
|
yield LogiCircle
|
||||||
return_value={"accountId": "testId"}
|
|
||||||
)
|
|
||||||
mock_logi_circle_.LogiCircle().authorize_url = "http://authorize.url"
|
|
||||||
yield mock_logi_circle_
|
|
||||||
|
|
||||||
|
|
||||||
async def test_step_import(
|
async def test_step_import(
|
||||||
|
@ -159,7 +152,7 @@ async def test_abort_if_authorize_fails(
|
||||||
): # pylint: disable=redefined-outer-name
|
): # pylint: disable=redefined-outer-name
|
||||||
"""Test we abort if authorizing fails."""
|
"""Test we abort if authorizing fails."""
|
||||||
flow = init_config_flow(hass)
|
flow = init_config_flow(hass)
|
||||||
mock_logi_circle.LogiCircle().authorize.side_effect = side_effect
|
mock_logi_circle.authorize.side_effect = side_effect
|
||||||
|
|
||||||
result = await flow.async_step_code("123ABC")
|
result = await flow.async_step_code("123ABC")
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
|
@ -219,4 +212,4 @@ async def test_callback_view_accepts_code(
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
mock_logi_circle.LogiCircle.return_value.authorize.assert_called_with("456")
|
mock_logi_circle.authorize.assert_called_with("456")
|
||||||
|
|
|
@ -3,6 +3,7 @@ import unittest
|
||||||
import unittest.mock as mock
|
import unittest.mock as mock
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from mficlient.client import FailedToLogin
|
||||||
|
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
import homeassistant.components.sensor as sensor
|
import homeassistant.components.sensor as sensor
|
||||||
|
@ -38,28 +39,26 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||||
"""Stop everything that was started."""
|
"""Stop everything that was started."""
|
||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
@mock.patch("mficlient.client.MFiClient")
|
@mock.patch("homeassistant.components.mfi.sensor.MFiClient")
|
||||||
def test_setup_missing_config(self, mock_client):
|
def test_setup_missing_config(self, mock_client):
|
||||||
"""Test setup with missing configuration."""
|
"""Test setup with missing configuration."""
|
||||||
config = {"sensor": {"platform": "mfi"}}
|
config = {"sensor": {"platform": "mfi"}}
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert setup_component(self.hass, "sensor", config)
|
||||||
assert not mock_client.called
|
assert not mock_client.called
|
||||||
|
|
||||||
@mock.patch("mficlient.client.MFiClient")
|
@mock.patch("homeassistant.components.mfi.sensor.MFiClient")
|
||||||
def test_setup_failed_login(self, mock_client):
|
def test_setup_failed_login(self, mock_client):
|
||||||
"""Test setup with login failure."""
|
"""Test setup with login failure."""
|
||||||
from mficlient.client import FailedToLogin
|
|
||||||
|
|
||||||
mock_client.side_effect = FailedToLogin
|
mock_client.side_effect = FailedToLogin
|
||||||
assert not self.PLATFORM.setup_platform(self.hass, dict(self.GOOD_CONFIG), None)
|
assert not self.PLATFORM.setup_platform(self.hass, dict(self.GOOD_CONFIG), None)
|
||||||
|
|
||||||
@mock.patch("mficlient.client.MFiClient")
|
@mock.patch("homeassistant.components.mfi.sensor.MFiClient")
|
||||||
def test_setup_failed_connect(self, mock_client):
|
def test_setup_failed_connect(self, mock_client):
|
||||||
"""Test setup with connection failure."""
|
"""Test setup with connection failure."""
|
||||||
mock_client.side_effect = requests.exceptions.ConnectionError
|
mock_client.side_effect = requests.exceptions.ConnectionError
|
||||||
assert not self.PLATFORM.setup_platform(self.hass, dict(self.GOOD_CONFIG), None)
|
assert not self.PLATFORM.setup_platform(self.hass, dict(self.GOOD_CONFIG), None)
|
||||||
|
|
||||||
@mock.patch("mficlient.client.MFiClient")
|
@mock.patch("homeassistant.components.mfi.sensor.MFiClient")
|
||||||
def test_setup_minimum(self, mock_client):
|
def test_setup_minimum(self, mock_client):
|
||||||
"""Test setup with minimum configuration."""
|
"""Test setup with minimum configuration."""
|
||||||
config = dict(self.GOOD_CONFIG)
|
config = dict(self.GOOD_CONFIG)
|
||||||
|
@ -70,7 +69,7 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||||
"foo", "user", "pass", port=6443, use_tls=True, verify=True
|
"foo", "user", "pass", port=6443, use_tls=True, verify=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("mficlient.client.MFiClient")
|
@mock.patch("homeassistant.components.mfi.sensor.MFiClient")
|
||||||
def test_setup_with_port(self, mock_client):
|
def test_setup_with_port(self, mock_client):
|
||||||
"""Test setup with port."""
|
"""Test setup with port."""
|
||||||
config = dict(self.GOOD_CONFIG)
|
config = dict(self.GOOD_CONFIG)
|
||||||
|
@ -81,7 +80,7 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||||
"foo", "user", "pass", port=6123, use_tls=True, verify=True
|
"foo", "user", "pass", port=6123, use_tls=True, verify=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("mficlient.client.MFiClient")
|
@mock.patch("homeassistant.components.mfi.sensor.MFiClient")
|
||||||
def test_setup_with_tls_disabled(self, mock_client):
|
def test_setup_with_tls_disabled(self, mock_client):
|
||||||
"""Test setup without TLS."""
|
"""Test setup without TLS."""
|
||||||
config = dict(self.GOOD_CONFIG)
|
config = dict(self.GOOD_CONFIG)
|
||||||
|
@ -94,7 +93,7 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||||
"foo", "user", "pass", port=6080, use_tls=False, verify=False
|
"foo", "user", "pass", port=6080, use_tls=False, verify=False
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("mficlient.client.MFiClient")
|
@mock.patch("homeassistant.components.mfi.sensor.MFiClient")
|
||||||
@mock.patch("homeassistant.components.mfi.sensor.MfiSensor")
|
@mock.patch("homeassistant.components.mfi.sensor.MfiSensor")
|
||||||
def test_setup_adds_proper_devices(self, mock_sensor, mock_client):
|
def test_setup_adds_proper_devices(self, mock_sensor, mock_client):
|
||||||
"""Test if setup adds devices."""
|
"""Test if setup adds devices."""
|
||||||
|
|
|
@ -5,12 +5,11 @@ import unittest.mock as mock
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
import homeassistant.components.switch as switch
|
import homeassistant.components.switch as switch
|
||||||
import homeassistant.components.mfi.switch as mfi
|
import homeassistant.components.mfi.switch as mfi
|
||||||
from tests.components.mfi import test_sensor as test_mfi_sensor
|
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant
|
from tests.common import get_test_home_assistant
|
||||||
|
|
||||||
|
|
||||||
class TestMfiSwitchSetup(test_mfi_sensor.TestMfiSensorSetup):
|
class TestMfiSwitchSetup(unittest.TestCase):
|
||||||
"""Test the mFi switch."""
|
"""Test the mFi switch."""
|
||||||
|
|
||||||
PLATFORM = mfi
|
PLATFORM = mfi
|
||||||
|
@ -28,7 +27,15 @@ class TestMfiSwitchSetup(test_mfi_sensor.TestMfiSensorSetup):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@mock.patch("mficlient.client.MFiClient")
|
def setup_method(self, method):
|
||||||
|
"""Set up things to be run when tests are started."""
|
||||||
|
self.hass = get_test_home_assistant()
|
||||||
|
|
||||||
|
def teardown_method(self, method):
|
||||||
|
"""Stop everything that was started."""
|
||||||
|
self.hass.stop()
|
||||||
|
|
||||||
|
@mock.patch("homeassistant.components.mfi.switch.MFiClient")
|
||||||
@mock.patch("homeassistant.components.mfi.switch.MfiSwitch")
|
@mock.patch("homeassistant.components.mfi.switch.MfiSwitch")
|
||||||
def test_setup_adds_proper_devices(self, mock_switch, mock_client):
|
def test_setup_adds_proper_devices(self, mock_switch, mock_client):
|
||||||
"""Test if setup adds devices."""
|
"""Test if setup adds devices."""
|
||||||
|
|
|
@ -7,7 +7,7 @@ import pytest
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.point import DOMAIN, config_flow
|
from homeassistant.components.point import DOMAIN, config_flow
|
||||||
|
|
||||||
from tests.common import MockDependency, mock_coro
|
from tests.common import mock_coro
|
||||||
|
|
||||||
|
|
||||||
def init_config_flow(hass, side_effect=None):
|
def init_config_flow(hass, side_effect=None):
|
||||||
|
@ -30,15 +30,15 @@ def is_authorized():
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_pypoint(is_authorized): # pylint: disable=redefined-outer-name
|
def mock_pypoint(is_authorized): # pylint: disable=redefined-outer-name
|
||||||
"""Mock pypoint."""
|
"""Mock pypoint."""
|
||||||
with MockDependency("pypoint") as mock_pypoint_:
|
with patch(
|
||||||
mock_pypoint_.PointSession().get_access_token.return_value = {
|
"homeassistant.components.point.config_flow.PointSession"
|
||||||
|
) as PointSession:
|
||||||
|
PointSession.return_value.get_access_token.return_value = {
|
||||||
"access_token": "boo"
|
"access_token": "boo"
|
||||||
}
|
}
|
||||||
mock_pypoint_.PointSession().is_authorized = is_authorized
|
PointSession.return_value.is_authorized = is_authorized
|
||||||
mock_pypoint_.PointSession().user.return_value = {
|
PointSession.return_value.user.return_value = {"email": "john.doe@example.com"}
|
||||||
"email": "john.doe@example.com"
|
yield PointSession
|
||||||
}
|
|
||||||
yield mock_pypoint_
|
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_no_implementation_registered(hass):
|
async def test_abort_if_no_implementation_registered(hass):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
"""Define tests for the OpenUV config flow."""
|
"""Define tests for the OpenUV config flow."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from regenmaschine.errors import RainMachineError
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.rainmachine import DOMAIN, config_flow
|
from homeassistant.components.rainmachine import DOMAIN, config_flow
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -33,8 +35,6 @@ async def test_duplicate_error(hass):
|
||||||
|
|
||||||
async def test_invalid_password(hass):
|
async def test_invalid_password(hass):
|
||||||
"""Test that an invalid password throws an error."""
|
"""Test that an invalid password throws an error."""
|
||||||
from regenmaschine.errors import RainMachineError
|
|
||||||
|
|
||||||
conf = {
|
conf = {
|
||||||
CONF_IP_ADDRESS: "192.168.1.100",
|
CONF_IP_ADDRESS: "192.168.1.100",
|
||||||
CONF_PASSWORD: "bad_password",
|
CONF_PASSWORD: "bad_password",
|
||||||
|
@ -46,7 +46,8 @@ async def test_invalid_password(hass):
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"regenmaschine.login", return_value=mock_coro(exception=RainMachineError)
|
"homeassistant.components.rainmachine.config_flow.login",
|
||||||
|
return_value=mock_coro(exception=RainMachineError),
|
||||||
):
|
):
|
||||||
result = await flow.async_step_user(user_input=conf)
|
result = await flow.async_step_user(user_input=conf)
|
||||||
assert result["errors"] == {CONF_PASSWORD: "invalid_credentials"}
|
assert result["errors"] == {CONF_PASSWORD: "invalid_credentials"}
|
||||||
|
@ -75,7 +76,10 @@ async def test_step_import(hass):
|
||||||
flow = config_flow.RainMachineFlowHandler()
|
flow = config_flow.RainMachineFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
||||||
with patch("regenmaschine.login", return_value=mock_coro(True)):
|
with patch(
|
||||||
|
"homeassistant.components.rainmachine.config_flow.login",
|
||||||
|
return_value=mock_coro(True),
|
||||||
|
):
|
||||||
result = await flow.async_step_import(import_config=conf)
|
result = await flow.async_step_import(import_config=conf)
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
|
@ -101,7 +105,10 @@ async def test_step_user(hass):
|
||||||
flow = config_flow.RainMachineFlowHandler()
|
flow = config_flow.RainMachineFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
||||||
with patch("regenmaschine.login", return_value=mock_coro(True)):
|
with patch(
|
||||||
|
"homeassistant.components.rainmachine.config_flow.login",
|
||||||
|
return_value=mock_coro(True),
|
||||||
|
):
|
||||||
result = await flow.async_step_user(user_input=conf)
|
result = await flow.async_step_user(user_input=conf)
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
|
|
|
@ -18,7 +18,7 @@ class TestRandomSensor(unittest.TestCase):
|
||||||
"""Stop everything that was started."""
|
"""Stop everything that was started."""
|
||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
@patch("random.getrandbits", return_value=1)
|
@patch("homeassistant.components.random.binary_sensor.getrandbits", return_value=1)
|
||||||
def test_random_binary_sensor_on(self, mocked):
|
def test_random_binary_sensor_on(self, mocked):
|
||||||
"""Test the Random binary sensor."""
|
"""Test the Random binary sensor."""
|
||||||
config = {"binary_sensor": {"platform": "random", "name": "test"}}
|
config = {"binary_sensor": {"platform": "random", "name": "test"}}
|
||||||
|
@ -29,7 +29,9 @@ class TestRandomSensor(unittest.TestCase):
|
||||||
|
|
||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
|
|
||||||
@patch("random.getrandbits", return_value=False)
|
@patch(
|
||||||
|
"homeassistant.components.random.binary_sensor.getrandbits", return_value=False
|
||||||
|
)
|
||||||
def test_random_binary_sensor_off(self, mocked):
|
def test_random_binary_sensor_off(self, mocked):
|
||||||
"""Test the Random binary sensor."""
|
"""Test the Random binary sensor."""
|
||||||
config = {"binary_sensor": {"platform": "random", "name": "test"}}
|
config = {"binary_sensor": {"platform": "random", "name": "test"}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue