core/tests/components/asuswrt/test_device_tracker.py

61 lines
1.8 KiB
Python
Raw Normal View History

"""The tests for the ASUSWRT device tracker platform."""
2019-12-05 06:47:40 +00:00
from unittest.mock import patch
from homeassistant.components.asuswrt import (
2019-07-31 19:25:30 +00:00
CONF_MODE,
CONF_PORT,
CONF_PROTOCOL,
2019-07-31 19:25:30 +00:00
DATA_ASUSWRT,
DOMAIN,
2019-07-31 19:25:30 +00:00
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PLATFORM, CONF_USERNAME
from homeassistant.setup import async_setup_component
2019-12-05 06:47:40 +00:00
from tests.common import mock_coro_func
FAKEFILE = None
2019-07-31 19:25:30 +00:00
VALID_CONFIG_ROUTER_SSH = {
DOMAIN: {
CONF_PLATFORM: "asuswrt",
CONF_HOST: "fake_host",
CONF_USERNAME: "fake_user",
CONF_PROTOCOL: "ssh",
CONF_MODE: "router",
CONF_PORT: "22",
}
}
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
result = await async_setup_component(
2019-07-31 19:25:30 +00:00
hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}}
)
assert not result
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={}
)
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",
}
},
)
assert result
assert hass.data[DATA_ASUSWRT] is not None