2018-11-07 17:32:13 +00:00
|
|
|
"""The tests for the ASUSWRT device tracker platform."""
|
2019-12-05 06:47:40 +00:00
|
|
|
from unittest.mock import patch
|
2018-11-07 17:32:13 +00:00
|
|
|
|
|
|
|
from homeassistant.components.asuswrt import (
|
2020-02-21 16:01:57 +00:00
|
|
|
CONF_DNSMASQ,
|
|
|
|
CONF_INTERFACE,
|
2019-07-31 19:25:30 +00:00
|
|
|
DATA_ASUSWRT,
|
2019-12-09 12:57:24 +00:00
|
|
|
DOMAIN,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2020-02-21 16:01:57 +00:00
|
|
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
2019-12-09 12:57:24 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2018-11-07 17:32:13 +00:00
|
|
|
|
2019-12-05 06:47:40 +00:00
|
|
|
from tests.common import mock_coro_func
|
2018-11-07 17:32:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_password_or_pub_key_required(hass):
|
|
|
|
"""Test creating an AsusWRT scanner without a pass or pubkey."""
|
2019-12-05 06:47:40 +00:00
|
|
|
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
|
|
|
|
AsusWrt().connection.async_connect = mock_coro_func()
|
|
|
|
AsusWrt().is_connected = False
|
2018-11-07 17:32:13 +00:00
|
|
|
result = await async_setup_component(
|
2020-04-01 18:04:44 +00:00
|
|
|
hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}}
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2018-11-07 17:32:13 +00:00
|
|
|
assert not result
|
|
|
|
|
|
|
|
|
2020-04-03 13:02:48 +00:00
|
|
|
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().is_connected = False
|
|
|
|
result = await async_setup_component(
|
|
|
|
hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}}
|
|
|
|
)
|
|
|
|
assert result
|
|
|
|
assert hass.data.get(DATA_ASUSWRT, None) is None
|
|
|
|
|
|
|
|
|
2018-11-07 17:32:13 +00:00
|
|
|
async def test_get_scanner_with_password_no_pubkey(hass):
|
|
|
|
"""Test creating an AsusWRT scanner with a password and no pubkey."""
|
2019-12-05 06:47:40 +00:00
|
|
|
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
|
|
|
|
AsusWrt().connection.async_connect = mock_coro_func()
|
|
|
|
AsusWrt().connection.async_get_connected_devices = mock_coro_func(
|
2019-07-31 19:25:30 +00:00
|
|
|
return_value={}
|
|
|
|
)
|
2018-11-07 17:32:13 +00:00
|
|
|
result = await async_setup_component(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass,
|
|
|
|
DOMAIN,
|
|
|
|
{
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_HOST: "fake_host",
|
|
|
|
CONF_USERNAME: "fake_user",
|
|
|
|
CONF_PASSWORD: "4321",
|
2020-02-21 16:01:57 +00:00
|
|
|
CONF_DNSMASQ: "/",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert result
|
|
|
|
assert hass.data[DATA_ASUSWRT] is not None
|
|
|
|
|
|
|
|
|
|
|
|
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().is_connected = False
|
|
|
|
result = await async_setup_component(
|
|
|
|
hass,
|
|
|
|
DOMAIN,
|
|
|
|
{
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_HOST: "fake_host",
|
|
|
|
CONF_USERNAME: "fake_user",
|
|
|
|
CONF_PASSWORD: "4321",
|
2020-04-01 18:04:44 +00:00
|
|
|
CONF_DNSMASQ: 1234,
|
2020-02-21 16:01:57 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert not result
|
|
|
|
|
|
|
|
|
|
|
|
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={}
|
|
|
|
)
|
|
|
|
result = await async_setup_component(
|
|
|
|
hass,
|
|
|
|
DOMAIN,
|
|
|
|
{
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_HOST: "fake_host",
|
|
|
|
CONF_USERNAME: "fake_user",
|
|
|
|
CONF_PASSWORD: "4321",
|
|
|
|
CONF_DNSMASQ: "/",
|
|
|
|
CONF_INTERFACE: "eth1",
|
2019-07-31 19:25:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-11-07 17:32:13 +00:00
|
|
|
assert result
|
|
|
|
assert hass.data[DATA_ASUSWRT] is not None
|
2020-02-21 16:01:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
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().is_connected = False
|
|
|
|
result = await async_setup_component(
|
|
|
|
hass,
|
|
|
|
DOMAIN,
|
|
|
|
{
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_HOST: "fake_host",
|
|
|
|
CONF_USERNAME: "fake_user",
|
|
|
|
CONF_PASSWORD: "4321",
|
|
|
|
CONF_DNSMASQ: "/",
|
|
|
|
CONF_INTERFACE: None,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert not result
|