Use voluptuous for Unifi, Ubus (#3125)
This commit is contained in:
parent
48e6befc13
commit
22362727e4
3 changed files with 52 additions and 59 deletions
|
@ -3,9 +3,12 @@ import unittest
|
|||
from unittest import mock
|
||||
import urllib
|
||||
|
||||
from homeassistant.components.device_tracker import unifi as unifi
|
||||
from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD
|
||||
from unifi import controller
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.device_tracker import DOMAIN, unifi as unifi
|
||||
from homeassistant.const import (CONF_HOST, CONF_USERNAME, CONF_PASSWORD,
|
||||
CONF_PLATFORM)
|
||||
|
||||
|
||||
class TestUnifiScanner(unittest.TestCase):
|
||||
|
@ -16,13 +19,14 @@ class TestUnifiScanner(unittest.TestCase):
|
|||
def test_config_minimal(self, mock_ctrl, mock_scanner):
|
||||
"""Test the setup with minimal configuration."""
|
||||
config = {
|
||||
'device_tracker': {
|
||||
DOMAIN: unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
}
|
||||
})
|
||||
}
|
||||
result = unifi.get_scanner(None, config)
|
||||
self.assertEqual(unifi.UnifiScanner.return_value, result)
|
||||
self.assertEqual(mock_scanner.return_value, result)
|
||||
mock_ctrl.assert_called_once_with('localhost', 'foo', 'password',
|
||||
8443, 'v4', 'default')
|
||||
mock_scanner.assert_called_once_with(mock_ctrl.return_value)
|
||||
|
@ -32,49 +36,38 @@ class TestUnifiScanner(unittest.TestCase):
|
|||
def test_config_full(self, mock_ctrl, mock_scanner):
|
||||
"""Test the setup with full configuration."""
|
||||
config = {
|
||||
'device_tracker': {
|
||||
DOMAIN: unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
CONF_HOST: 'myhost',
|
||||
'port': 123,
|
||||
'site_id': 'abcdef01',
|
||||
}
|
||||
})
|
||||
}
|
||||
result = unifi.get_scanner(None, config)
|
||||
self.assertEqual(unifi.UnifiScanner.return_value, result)
|
||||
self.assertEqual(mock_scanner.return_value, result)
|
||||
mock_ctrl.assert_called_once_with('myhost', 'foo', 'password',
|
||||
123, 'v4', 'abcdef01')
|
||||
mock_scanner.assert_called_once_with(mock_ctrl.return_value)
|
||||
|
||||
@mock.patch('homeassistant.components.device_tracker.unifi.UnifiScanner')
|
||||
@mock.patch.object(controller, 'Controller')
|
||||
def test_config_error(self, mock_ctrl, mock_scanner):
|
||||
def test_config_error(self):
|
||||
"""Test for configuration errors."""
|
||||
config = {
|
||||
'device_tracker': {
|
||||
with self.assertRaises(vol.Invalid):
|
||||
unifi.PLATFORM_SCHEMA({
|
||||
# no username
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_HOST: 'myhost',
|
||||
'port': 123,
|
||||
}
|
||||
}
|
||||
result = unifi.get_scanner(None, config)
|
||||
self.assertFalse(result)
|
||||
self.assertFalse(mock_ctrl.called)
|
||||
|
||||
@mock.patch('homeassistant.components.device_tracker.unifi.UnifiScanner')
|
||||
@mock.patch.object(controller, 'Controller')
|
||||
def test_config_badport(self, mock_ctrl, mock_scanner):
|
||||
"""Test the setup with a bad port."""
|
||||
config = {
|
||||
'device_tracker': {
|
||||
})
|
||||
with self.assertRaises(vol.Invalid):
|
||||
unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
CONF_HOST: 'myhost',
|
||||
'port': 'foo',
|
||||
}
|
||||
}
|
||||
result = unifi.get_scanner(None, config)
|
||||
self.assertFalse(result)
|
||||
self.assertFalse(mock_ctrl.called)
|
||||
'port': 'foo', # bad port!
|
||||
})
|
||||
|
||||
@mock.patch('homeassistant.components.device_tracker.unifi.UnifiScanner')
|
||||
@mock.patch.object(controller, 'Controller')
|
||||
|
@ -82,6 +75,7 @@ class TestUnifiScanner(unittest.TestCase):
|
|||
"""Test for controller failure."""
|
||||
config = {
|
||||
'device_tracker': {
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
}
|
||||
|
@ -91,7 +85,7 @@ class TestUnifiScanner(unittest.TestCase):
|
|||
result = unifi.get_scanner(None, config)
|
||||
self.assertFalse(result)
|
||||
|
||||
def test_scanner_update(self):
|
||||
def test_scanner_update(self): # pylint: disable=no-self-use
|
||||
"""Test the scanner update."""
|
||||
ctrl = mock.MagicMock()
|
||||
fake_clients = [
|
||||
|
@ -102,7 +96,7 @@ class TestUnifiScanner(unittest.TestCase):
|
|||
unifi.UnifiScanner(ctrl)
|
||||
ctrl.get_clients.assert_called_once_with()
|
||||
|
||||
def test_scanner_update_error(self):
|
||||
def test_scanner_update_error(self): # pylint: disable=no-self-use
|
||||
"""Test the scanner update for error."""
|
||||
ctrl = mock.MagicMock()
|
||||
ctrl.get_clients.side_effect = urllib.error.HTTPError(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue