Use a future for mock coro (#34989)

This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-04-30 16:31:00 -07:00
1 parent ba7391528f
commit 76f392476b
26 files changed
+154 -262

No files matched your search

@@ -1,5 +1,4 @@
"""The tests for the ASUSWRT device tracker platform."""
from unittest.mock import patch
from homeassistant.components.asuswrt import (
CONF_DNSMASQ,
@@ -10,13 +9,13 @@ from homeassistant.components.asuswrt import (
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.setup import async_setup_component
from tests.common import mock_coro_func
from tests.async_mock import AsyncMock, patch
async def test_password_or_pub_key_required(hass):
"""Test creating an AsusWRT scanner without a pass or pubkey."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func()
AsusWrt().connection.async_connect = AsyncMock()
AsusWrt().is_connected = False
result = await async_setup_component(
hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}}
@@ -27,7 +26,7 @@ async def test_password_or_pub_key_required(hass):
async def test_network_unreachable(hass):
"""Test creating an AsusWRT scanner without a pass or pubkey."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func(exception=OSError)
AsusWrt().connection.async_connect = AsyncMock(side_effect=OSError)
AsusWrt().is_connected = False
result = await async_setup_component(
hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}}
@@ -39,10 +38,8 @@ async def test_network_unreachable(hass):
async def test_get_scanner_with_password_no_pubkey(hass):
"""Test creating an AsusWRT scanner with a password and no pubkey."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func()
AsusWrt().connection.async_get_connected_devices = mock_coro_func(
return_value={}
)
AsusWrt().connection.async_connect = AsyncMock()
AsusWrt().connection.async_get_connected_devices = AsyncMock(return_value={})
result = await async_setup_component(
hass,
DOMAIN,
@@ -62,7 +59,7 @@ async def test_get_scanner_with_password_no_pubkey(hass):
async def test_specify_non_directory_path_for_dnsmasq(hass):
"""Test creating an AsusWRT scanner with a dnsmasq location which is not a valid directory."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func()
AsusWrt().connection.async_connect = AsyncMock()
AsusWrt().is_connected = False
result = await async_setup_component(
hass,
@@ -82,10 +79,8 @@ async def test_specify_non_directory_path_for_dnsmasq(hass):
async def test_interface(hass):
"""Test creating an AsusWRT scanner using interface eth1."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func()
AsusWrt().connection.async_get_connected_devices = mock_coro_func(
return_value={}
)
AsusWrt().connection.async_connect = AsyncMock()
AsusWrt().connection.async_get_connected_devices = AsyncMock(return_value={})
result = await async_setup_component(
hass,
DOMAIN,
@@ -106,7 +101,7 @@ async def test_interface(hass):
async def test_no_interface(hass):
"""Test creating an AsusWRT scanner using no interface."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func()
AsusWrt().connection.async_connect = AsyncMock()
AsusWrt().is_connected = False
result = await async_setup_component(
hass,