Remove more test requirements (#7574)
* No longer require pyunify during tests * No longer require cast during tests * No longer required dependency for tests * No longer require pymochad for tests * Astral is a core dependency * Avoid having to install datadog dependency during tests * CMUS test doesn't test anything * Frontier Silicon doesn't test anything * No longer require mutagen * Update requirements_test_all.txt * Remove stale commentpull/7589/head
parent
206d02d531
commit
352cca1037
|
@ -37,18 +37,12 @@ aiohttp_cors==0.5.3
|
||||||
# homeassistant.components.notify.apns
|
# homeassistant.components.notify.apns
|
||||||
apns2==0.1.1
|
apns2==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.datadog
|
|
||||||
datadog==0.15.0
|
|
||||||
|
|
||||||
# homeassistant.components.sensor.dsmr
|
# homeassistant.components.sensor.dsmr
|
||||||
dsmr_parser==0.8
|
dsmr_parser==0.8
|
||||||
|
|
||||||
# homeassistant.components.climate.honeywell
|
# homeassistant.components.climate.honeywell
|
||||||
evohomeclient==0.2.5
|
evohomeclient==0.2.5
|
||||||
|
|
||||||
# homeassistant.components.media_player.frontier_silicon
|
|
||||||
fsapi==0.0.7
|
|
||||||
|
|
||||||
# homeassistant.components.conversation
|
# homeassistant.components.conversation
|
||||||
fuzzywuzzy==0.15.0
|
fuzzywuzzy==0.15.0
|
||||||
|
|
||||||
|
@ -75,9 +69,6 @@ libsoundtouch==0.3.0
|
||||||
# homeassistant.components.switch.mfi
|
# homeassistant.components.switch.mfi
|
||||||
mficlient==0.3.0
|
mficlient==0.3.0
|
||||||
|
|
||||||
# homeassistant.components.tts
|
|
||||||
mutagen==1.37.0
|
|
||||||
|
|
||||||
# homeassistant.components.mqtt
|
# homeassistant.components.mqtt
|
||||||
paho-mqtt==1.2.3
|
paho-mqtt==1.2.3
|
||||||
|
|
||||||
|
@ -94,21 +85,12 @@ pilight==0.1.1
|
||||||
# homeassistant.components.sensor.serial_pm
|
# homeassistant.components.sensor.serial_pm
|
||||||
pmsensor==0.4
|
pmsensor==0.4
|
||||||
|
|
||||||
# homeassistant.components.media_player.cast
|
|
||||||
pychromecast==0.8.1
|
|
||||||
|
|
||||||
# homeassistant.components.media_player.cmus
|
|
||||||
pycmus==0.1.0
|
|
||||||
|
|
||||||
# homeassistant.components.zwave
|
# homeassistant.components.zwave
|
||||||
pydispatcher==2.0.5
|
pydispatcher==2.0.5
|
||||||
|
|
||||||
# homeassistant.components.litejet
|
# homeassistant.components.litejet
|
||||||
pylitejet==0.1
|
pylitejet==0.1
|
||||||
|
|
||||||
# homeassistant.components.mochad
|
|
||||||
pymochad==0.1.1
|
|
||||||
|
|
||||||
# homeassistant.components.alarm_control_panel.nx584
|
# homeassistant.components.alarm_control_panel.nx584
|
||||||
# homeassistant.components.binary_sensor.nx584
|
# homeassistant.components.binary_sensor.nx584
|
||||||
pynx584==0.4
|
pynx584==0.4
|
||||||
|
@ -116,9 +98,6 @@ pynx584==0.4
|
||||||
# homeassistant.components.sensor.darksky
|
# homeassistant.components.sensor.darksky
|
||||||
python-forecastio==1.3.5
|
python-forecastio==1.3.5
|
||||||
|
|
||||||
# homeassistant.components.device_tracker.unifi
|
|
||||||
pyunifi==2.12
|
|
||||||
|
|
||||||
# homeassistant.components.notify.html5
|
# homeassistant.components.notify.html5
|
||||||
pywebpush==1.0.0
|
pywebpush==1.0.0
|
||||||
|
|
||||||
|
|
|
@ -38,18 +38,15 @@ TEST_REQUIREMENTS = (
|
||||||
'uvcclient',
|
'uvcclient',
|
||||||
'somecomfort',
|
'somecomfort',
|
||||||
'aioautomatic',
|
'aioautomatic',
|
||||||
'pyunifi',
|
|
||||||
'SoCo',
|
'SoCo',
|
||||||
'libsoundtouch',
|
'libsoundtouch',
|
||||||
'rxv',
|
'rxv',
|
||||||
'apns2',
|
'apns2',
|
||||||
'sqlalchemy',
|
'sqlalchemy',
|
||||||
'forecastio',
|
'forecastio',
|
||||||
'astral',
|
|
||||||
'aiohttp_cors',
|
'aiohttp_cors',
|
||||||
'pilight',
|
'pilight',
|
||||||
'fuzzywuzzy',
|
'fuzzywuzzy',
|
||||||
'datadog',
|
|
||||||
'rflink',
|
'rflink',
|
||||||
'ring_doorbell',
|
'ring_doorbell',
|
||||||
'sleepyq',
|
'sleepyq',
|
||||||
|
@ -59,21 +56,14 @@ TEST_REQUIREMENTS = (
|
||||||
'evohomeclient',
|
'evohomeclient',
|
||||||
'pexpect',
|
'pexpect',
|
||||||
'hbmqtt',
|
'hbmqtt',
|
||||||
'pychromecast',
|
|
||||||
'pycmus',
|
|
||||||
'fsapi',
|
|
||||||
'paho',
|
'paho',
|
||||||
'jwt',
|
|
||||||
'dsmr_parser',
|
'dsmr_parser',
|
||||||
'mficlient',
|
'mficlient',
|
||||||
'pmsensor',
|
'pmsensor',
|
||||||
'yahoo-finance',
|
'yahoo-finance',
|
||||||
'pymochad',
|
|
||||||
'mutagen',
|
|
||||||
'ha-ffmpeg',
|
'ha-ffmpeg',
|
||||||
'gTTS-token',
|
'gTTS-token',
|
||||||
'pywebpush',
|
'pywebpush',
|
||||||
'pyelliptic',
|
|
||||||
'PyJWT',
|
'PyJWT',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -495,3 +495,38 @@ def mock_restore_cache(hass, states):
|
||||||
"Duplicate entity_id? {}".format(states)
|
"Duplicate entity_id? {}".format(states)
|
||||||
hass.state = ha.CoreState.starting
|
hass.state = ha.CoreState.starting
|
||||||
mock_component(hass, recorder.DOMAIN)
|
mock_component(hass, recorder.DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
|
class MockDependency:
|
||||||
|
"""Decorator to mock install a dependency."""
|
||||||
|
|
||||||
|
def __init__(self, root, *args):
|
||||||
|
"""Initialize decorator."""
|
||||||
|
self.root = root
|
||||||
|
self.submodules = args
|
||||||
|
|
||||||
|
def __call__(self, func):
|
||||||
|
"""Apply decorator."""
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
def resolve(mock, path):
|
||||||
|
"""Resolve a mock."""
|
||||||
|
if not path:
|
||||||
|
return mock
|
||||||
|
|
||||||
|
return resolve(getattr(mock, path[0]), path[1:])
|
||||||
|
|
||||||
|
def run_mocked(*args, **kwargs):
|
||||||
|
"""Run with mocked dependencies."""
|
||||||
|
base = MagicMock()
|
||||||
|
to_mock = {
|
||||||
|
"{}.{}".format(self.root, tom): resolve(base, tom.split('.'))
|
||||||
|
for tom in self.submodules
|
||||||
|
}
|
||||||
|
to_mock[self.root] = base
|
||||||
|
|
||||||
|
with patch.dict('sys.modules', to_mock):
|
||||||
|
args = list(args) + [base]
|
||||||
|
func(*args, **kwargs)
|
||||||
|
|
||||||
|
return run_mocked
|
||||||
|
|
|
@ -1,157 +1,155 @@
|
||||||
"""The tests for the Unifi WAP device tracker platform."""
|
"""The tests for the Unifi WAP device tracker platform."""
|
||||||
import unittest
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from pyunifi import controller
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant
|
|
||||||
from homeassistant.components.device_tracker import DOMAIN, unifi as unifi
|
from homeassistant.components.device_tracker import DOMAIN, unifi as unifi
|
||||||
from homeassistant.const import (CONF_HOST, CONF_USERNAME, CONF_PASSWORD,
|
from homeassistant.const import (CONF_HOST, CONF_USERNAME, CONF_PASSWORD,
|
||||||
CONF_PLATFORM, CONF_VERIFY_SSL)
|
CONF_PLATFORM, CONF_VERIFY_SSL)
|
||||||
|
|
||||||
|
|
||||||
class TestUnifiScanner(unittest.TestCase):
|
@pytest.fixture
|
||||||
"""Test the Unifiy platform."""
|
def mock_ctrl():
|
||||||
|
"""Mock pyunifi."""
|
||||||
|
module = mock.MagicMock()
|
||||||
|
with mock.patch.dict('sys.modules', {
|
||||||
|
'pyunifi.controller': module.controller,
|
||||||
|
}):
|
||||||
|
yield module.controller.Controller
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
"""Initialize values for this testcase class."""
|
|
||||||
self.hass = get_test_home_assistant()
|
|
||||||
|
|
||||||
def tearDown(self):
|
@pytest.fixture
|
||||||
"""Stop everything that was started."""
|
def mock_scanner():
|
||||||
self.hass.stop()
|
"""Mock UnifyScanner."""
|
||||||
|
with mock.patch('homeassistant.components.device_tracker'
|
||||||
|
'.unifi.UnifiScanner') as scanner:
|
||||||
|
yield scanner
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.device_tracker.unifi.UnifiScanner')
|
|
||||||
@mock.patch.object(controller, 'Controller')
|
def test_config_minimal(hass, mock_scanner, mock_ctrl):
|
||||||
def test_config_minimal(self, mock_ctrl, mock_scanner):
|
"""Test the setup with minimal configuration."""
|
||||||
"""Test the setup with minimal configuration."""
|
config = {
|
||||||
config = {
|
DOMAIN: unifi.PLATFORM_SCHEMA({
|
||||||
DOMAIN: unifi.PLATFORM_SCHEMA({
|
CONF_PLATFORM: unifi.DOMAIN,
|
||||||
CONF_PLATFORM: unifi.DOMAIN,
|
CONF_USERNAME: 'foo',
|
||||||
CONF_USERNAME: 'foo',
|
CONF_PASSWORD: 'password',
|
||||||
CONF_PASSWORD: 'password',
|
})
|
||||||
})
|
}
|
||||||
|
result = unifi.get_scanner(hass, config)
|
||||||
|
assert mock_scanner.return_value == result
|
||||||
|
assert mock_ctrl.call_count == 1
|
||||||
|
assert mock_ctrl.mock_calls[0] == \
|
||||||
|
mock.call('localhost', 'foo', 'password', 8443,
|
||||||
|
version='v4', site_id='default', ssl_verify=True)
|
||||||
|
|
||||||
|
assert mock_scanner.call_count == 1
|
||||||
|
assert mock_scanner.call_args == mock.call(mock_ctrl.return_value)
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_full(hass, mock_scanner, mock_ctrl):
|
||||||
|
"""Test the setup with full configuration."""
|
||||||
|
config = {
|
||||||
|
DOMAIN: unifi.PLATFORM_SCHEMA({
|
||||||
|
CONF_PLATFORM: unifi.DOMAIN,
|
||||||
|
CONF_USERNAME: 'foo',
|
||||||
|
CONF_PASSWORD: 'password',
|
||||||
|
CONF_HOST: 'myhost',
|
||||||
|
CONF_VERIFY_SSL: False,
|
||||||
|
'port': 123,
|
||||||
|
'site_id': 'abcdef01',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
result = unifi.get_scanner(hass, config)
|
||||||
|
assert mock_scanner.return_value == result
|
||||||
|
assert mock_ctrl.call_count == 1
|
||||||
|
assert mock_ctrl.call_args == \
|
||||||
|
mock.call('myhost', 'foo', 'password', 123,
|
||||||
|
version='v4', site_id='abcdef01', ssl_verify=False)
|
||||||
|
|
||||||
|
assert mock_scanner.call_count == 1
|
||||||
|
assert mock_scanner.call_args == mock.call(mock_ctrl.return_value)
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_error():
|
||||||
|
"""Test for configuration errors."""
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
unifi.PLATFORM_SCHEMA({
|
||||||
|
# no username
|
||||||
|
CONF_PLATFORM: unifi.DOMAIN,
|
||||||
|
CONF_HOST: 'myhost',
|
||||||
|
'port': 123,
|
||||||
|
})
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
unifi.PLATFORM_SCHEMA({
|
||||||
|
CONF_PLATFORM: unifi.DOMAIN,
|
||||||
|
CONF_USERNAME: 'foo',
|
||||||
|
CONF_PASSWORD: 'password',
|
||||||
|
CONF_HOST: 'myhost',
|
||||||
|
'port': 'foo', # bad port!
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_controller_failed(hass, mock_ctrl, mock_scanner):
|
||||||
|
"""Test for controller failure."""
|
||||||
|
config = {
|
||||||
|
'device_tracker': {
|
||||||
|
CONF_PLATFORM: unifi.DOMAIN,
|
||||||
|
CONF_USERNAME: 'foo',
|
||||||
|
CONF_PASSWORD: 'password',
|
||||||
}
|
}
|
||||||
result = unifi.get_scanner(self.hass, config)
|
}
|
||||||
self.assertEqual(mock_scanner.return_value, result)
|
mock_ctrl.side_effect = urllib.error.HTTPError(
|
||||||
self.assertEqual(mock_ctrl.call_count, 1)
|
'/', 500, 'foo', {}, None)
|
||||||
self.assertEqual(
|
result = unifi.get_scanner(hass, config)
|
||||||
mock_ctrl.call_args,
|
assert result is False
|
||||||
mock.call('localhost', 'foo', 'password', 8443,
|
|
||||||
version='v4', site_id='default', ssl_verify=True)
|
|
||||||
)
|
|
||||||
self.assertEqual(mock_scanner.call_count, 1)
|
|
||||||
self.assertEqual(
|
|
||||||
mock_scanner.call_args,
|
|
||||||
mock.call(mock_ctrl.return_value)
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.device_tracker.unifi.UnifiScanner')
|
|
||||||
@mock.patch.object(controller, 'Controller')
|
|
||||||
def test_config_full(self, mock_ctrl, mock_scanner):
|
|
||||||
"""Test the setup with full configuration."""
|
|
||||||
config = {
|
|
||||||
DOMAIN: unifi.PLATFORM_SCHEMA({
|
|
||||||
CONF_PLATFORM: unifi.DOMAIN,
|
|
||||||
CONF_USERNAME: 'foo',
|
|
||||||
CONF_PASSWORD: 'password',
|
|
||||||
CONF_HOST: 'myhost',
|
|
||||||
CONF_VERIFY_SSL: False,
|
|
||||||
'port': 123,
|
|
||||||
'site_id': 'abcdef01',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
result = unifi.get_scanner(self.hass, config)
|
|
||||||
self.assertEqual(mock_scanner.return_value, result)
|
|
||||||
self.assertEqual(mock_ctrl.call_count, 1)
|
|
||||||
self.assertEqual(
|
|
||||||
mock_ctrl.call_args,
|
|
||||||
mock.call('myhost', 'foo', 'password', 123,
|
|
||||||
version='v4', site_id='abcdef01', ssl_verify=False)
|
|
||||||
)
|
|
||||||
self.assertEqual(mock_scanner.call_count, 1)
|
|
||||||
self.assertEqual(
|
|
||||||
mock_scanner.call_args,
|
|
||||||
mock.call(mock_ctrl.return_value)
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_config_error(self):
|
def test_scanner_update():
|
||||||
"""Test for configuration errors."""
|
"""Test the scanner update."""
|
||||||
with self.assertRaises(vol.Invalid):
|
ctrl = mock.MagicMock()
|
||||||
unifi.PLATFORM_SCHEMA({
|
fake_clients = [
|
||||||
# no username
|
{'mac': '123'},
|
||||||
CONF_PLATFORM: unifi.DOMAIN,
|
{'mac': '234'},
|
||||||
CONF_HOST: 'myhost',
|
]
|
||||||
'port': 123,
|
ctrl.get_clients.return_value = fake_clients
|
||||||
})
|
unifi.UnifiScanner(ctrl)
|
||||||
with self.assertRaises(vol.Invalid):
|
assert ctrl.get_clients.call_count == 1
|
||||||
unifi.PLATFORM_SCHEMA({
|
assert ctrl.get_clients.call_args == mock.call()
|
||||||
CONF_PLATFORM: unifi.DOMAIN,
|
|
||||||
CONF_USERNAME: 'foo',
|
|
||||||
CONF_PASSWORD: 'password',
|
|
||||||
CONF_HOST: 'myhost',
|
|
||||||
'port': 'foo', # bad port!
|
|
||||||
})
|
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.device_tracker.unifi.UnifiScanner')
|
|
||||||
@mock.patch.object(controller, 'Controller')
|
|
||||||
def test_config_controller_failed(self, mock_ctrl, mock_scanner):
|
|
||||||
"""Test for controller failure."""
|
|
||||||
config = {
|
|
||||||
'device_tracker': {
|
|
||||||
CONF_PLATFORM: unifi.DOMAIN,
|
|
||||||
CONF_USERNAME: 'foo',
|
|
||||||
CONF_PASSWORD: 'password',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mock_ctrl.side_effect = urllib.error.HTTPError(
|
|
||||||
'/', 500, 'foo', {}, None)
|
|
||||||
result = unifi.get_scanner(self.hass, config)
|
|
||||||
self.assertFalse(result)
|
|
||||||
|
|
||||||
def test_scanner_update(self): # pylint: disable=no-self-use
|
def test_scanner_update_error():
|
||||||
"""Test the scanner update."""
|
"""Test the scanner update for error."""
|
||||||
ctrl = mock.MagicMock()
|
ctrl = mock.MagicMock()
|
||||||
fake_clients = [
|
ctrl.get_clients.side_effect = urllib.error.HTTPError(
|
||||||
{'mac': '123'},
|
'/', 500, 'foo', {}, None)
|
||||||
{'mac': '234'},
|
unifi.UnifiScanner(ctrl)
|
||||||
]
|
|
||||||
ctrl.get_clients.return_value = fake_clients
|
|
||||||
unifi.UnifiScanner(ctrl)
|
|
||||||
self.assertEqual(ctrl.get_clients.call_count, 1)
|
|
||||||
self.assertEqual(ctrl.get_clients.call_args, mock.call())
|
|
||||||
|
|
||||||
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(
|
|
||||||
'/', 500, 'foo', {}, None)
|
|
||||||
unifi.UnifiScanner(ctrl)
|
|
||||||
|
|
||||||
def test_scan_devices(self):
|
def test_scan_devices():
|
||||||
"""Test the scanning for devices."""
|
"""Test the scanning for devices."""
|
||||||
ctrl = mock.MagicMock()
|
ctrl = mock.MagicMock()
|
||||||
fake_clients = [
|
fake_clients = [
|
||||||
{'mac': '123'},
|
{'mac': '123'},
|
||||||
{'mac': '234'},
|
{'mac': '234'},
|
||||||
]
|
]
|
||||||
ctrl.get_clients.return_value = fake_clients
|
ctrl.get_clients.return_value = fake_clients
|
||||||
scanner = unifi.UnifiScanner(ctrl)
|
scanner = unifi.UnifiScanner(ctrl)
|
||||||
self.assertEqual(set(['123', '234']), set(scanner.scan_devices()))
|
assert set(scanner.scan_devices()) == set(['123', '234'])
|
||||||
|
|
||||||
def test_get_device_name(self):
|
|
||||||
"""Test the getting of device names."""
|
def test_get_device_name():
|
||||||
ctrl = mock.MagicMock()
|
"""Test the getting of device names."""
|
||||||
fake_clients = [
|
ctrl = mock.MagicMock()
|
||||||
{'mac': '123', 'hostname': 'foobar'},
|
fake_clients = [
|
||||||
{'mac': '234', 'name': 'Nice Name'},
|
{'mac': '123', 'hostname': 'foobar'},
|
||||||
{'mac': '456'},
|
{'mac': '234', 'name': 'Nice Name'},
|
||||||
]
|
{'mac': '456'},
|
||||||
ctrl.get_clients.return_value = fake_clients
|
]
|
||||||
scanner = unifi.UnifiScanner(ctrl)
|
ctrl.get_clients.return_value = fake_clients
|
||||||
self.assertEqual('foobar', scanner.get_device_name('123'))
|
scanner = unifi.UnifiScanner(ctrl)
|
||||||
self.assertEqual('Nice Name', scanner.get_device_name('234'))
|
assert scanner.get_device_name('123') == 'foobar'
|
||||||
self.assertEqual(None, scanner.get_device_name('456'))
|
assert scanner.get_device_name('234') == 'Nice Name'
|
||||||
self.assertEqual(None, scanner.get_device_name('unknown'))
|
assert scanner.get_device_name('456') is None
|
||||||
|
assert scanner.get_device_name('unknown') is None
|
||||||
|
|
|
@ -1,11 +1,22 @@
|
||||||
"""The tests for the Cast Media player platform."""
|
"""The tests for the Cast Media player platform."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch, MagicMock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.media_player import cast
|
from homeassistant.components.media_player import cast
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def cast_mock():
|
||||||
|
"""Mock pychromecast."""
|
||||||
|
with patch.dict('sys.modules', {
|
||||||
|
'pychromecast': MagicMock(),
|
||||||
|
}):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
class FakeChromeCast(object):
|
class FakeChromeCast(object):
|
||||||
"""A fake Chrome Cast."""
|
"""A fake Chrome Cast."""
|
||||||
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
"""The tests for the Demo Media player platform."""
|
|
||||||
import unittest
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
from homeassistant.components.media_player import cmus
|
|
||||||
from homeassistant import const
|
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant
|
|
||||||
|
|
||||||
entity_id = 'media_player.cmus'
|
|
||||||
|
|
||||||
|
|
||||||
class TestCmusMediaPlayer(unittest.TestCase):
|
|
||||||
"""Test the media_player module."""
|
|
||||||
|
|
||||||
def setUp(self): # pylint: disable=invalid-name
|
|
||||||
"""Setup things to be run when tests are started."""
|
|
||||||
self.hass = get_test_home_assistant()
|
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
|
||||||
"""Stop everything that was started."""
|
|
||||||
self.hass.stop()
|
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.media_player.cmus.CmusDevice')
|
|
||||||
def test_password_required_with_host(self, cmus_mock):
|
|
||||||
"""Test that a password is required when specifying a remote host."""
|
|
||||||
fake_config = {
|
|
||||||
const.CONF_HOST: 'a_real_hostname',
|
|
||||||
}
|
|
||||||
self.assertFalse(
|
|
||||||
cmus.setup_platform(self.hass, fake_config, mock.MagicMock()))
|
|
|
@ -1,42 +0,0 @@
|
||||||
"""The tests for the Demo Media player platform."""
|
|
||||||
import unittest
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from homeassistant.components.media_player.frontier_silicon import FSAPIDevice
|
|
||||||
from homeassistant.components.media_player import frontier_silicon
|
|
||||||
from homeassistant import const
|
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class TestFrontierSiliconMediaPlayer(unittest.TestCase):
|
|
||||||
"""Test the media_player module."""
|
|
||||||
|
|
||||||
def setUp(self): # pylint: disable=invalid-name
|
|
||||||
"""Setup things to be run when tests are started."""
|
|
||||||
self.hass = get_test_home_assistant()
|
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
|
||||||
"""Stop everything that was started."""
|
|
||||||
self.hass.stop()
|
|
||||||
|
|
||||||
def test_host_required_with_host(self):
|
|
||||||
"""Test that a host with a valid url is set when using a conf."""
|
|
||||||
fake_config = {
|
|
||||||
const.CONF_HOST: 'host_ip',
|
|
||||||
}
|
|
||||||
result = frontier_silicon.setup_platform(self.hass,
|
|
||||||
fake_config, mock.MagicMock())
|
|
||||||
|
|
||||||
self.assertTrue(result)
|
|
||||||
|
|
||||||
def test_invalid_host(self):
|
|
||||||
"""Test that a host with a valid url is set when using a conf."""
|
|
||||||
import requests
|
|
||||||
|
|
||||||
fsapi = FSAPIDevice('INVALID_URL', '1234')
|
|
||||||
self.assertRaises(requests.exceptions.MissingSchema, fsapi.update)
|
|
|
@ -2,6 +2,8 @@
|
||||||
import unittest
|
import unittest
|
||||||
import unittest.mock as mock
|
import unittest.mock as mock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
from homeassistant.components import switch
|
from homeassistant.components import switch
|
||||||
from homeassistant.components.switch import mochad
|
from homeassistant.components.switch import mochad
|
||||||
|
@ -9,6 +11,15 @@ from homeassistant.components.switch import mochad
|
||||||
from tests.common import get_test_home_assistant
|
from tests.common import get_test_home_assistant
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def pymochad_mock():
|
||||||
|
"""Mock pymochad."""
|
||||||
|
with mock.patch.dict('sys.modules', {
|
||||||
|
'pymochad': mock.MagicMock(),
|
||||||
|
}):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
class TestMochadSwitchSetup(unittest.TestCase):
|
class TestMochadSwitchSetup(unittest.TestCase):
|
||||||
"""Test the mochad switch."""
|
"""Test the mochad switch."""
|
||||||
|
|
||||||
|
@ -18,17 +29,14 @@ class TestMochadSwitchSetup(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Setup things to be run when tests are started."""
|
"""Setup things to be run when tests are started."""
|
||||||
super(TestMochadSwitchSetup, self).setUp()
|
|
||||||
self.hass = get_test_home_assistant()
|
self.hass = get_test_home_assistant()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
"""Stop everyhing that was started."""
|
"""Stop everyhing that was started."""
|
||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
super(TestMochadSwitchSetup, self).tearDown()
|
|
||||||
|
|
||||||
@mock.patch('pymochad.controller.PyMochad')
|
|
||||||
@mock.patch('homeassistant.components.switch.mochad.MochadSwitch')
|
@mock.patch('homeassistant.components.switch.mochad.MochadSwitch')
|
||||||
def test_setup_adds_proper_devices(self, mock_switch, mock_client):
|
def test_setup_adds_proper_devices(self, mock_switch):
|
||||||
"""Test if setup adds devices."""
|
"""Test if setup adds devices."""
|
||||||
good_config = {
|
good_config = {
|
||||||
'mochad': {},
|
'mochad': {},
|
||||||
|
@ -50,12 +58,8 @@ class TestMochadSwitch(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Setup things to be run when tests are started."""
|
"""Setup things to be run when tests are started."""
|
||||||
super(TestMochadSwitch, self).setUp()
|
|
||||||
self.hass = get_test_home_assistant()
|
self.hass = get_test_home_assistant()
|
||||||
controller_mock = mock.MagicMock()
|
controller_mock = mock.MagicMock()
|
||||||
device_patch = mock.patch('pymochad.device.Device')
|
|
||||||
device_patch.start()
|
|
||||||
self.addCleanup(device_patch.stop)
|
|
||||||
dev_dict = {'address': 'a1', 'name': 'fake_switch'}
|
dev_dict = {'address': 'a1', 'name': 'fake_switch'}
|
||||||
self.switch = mochad.MochadSwitch(self.hass, controller_mock,
|
self.switch = mochad.MochadSwitch(self.hass, controller_mock,
|
||||||
dev_dict)
|
dev_dict)
|
||||||
|
|
|
@ -12,7 +12,8 @@ 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)
|
from tests.common import (assert_setup_component, get_test_home_assistant,
|
||||||
|
MockDependency)
|
||||||
|
|
||||||
|
|
||||||
class TestDatadog(unittest.TestCase):
|
class TestDatadog(unittest.TestCase):
|
||||||
|
@ -35,10 +36,11 @@ class TestDatadog(unittest.TestCase):
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@mock.patch('datadog.initialize')
|
@MockDependency('datadog', 'beer')
|
||||||
def test_datadog_setup_full(self, mock_connection):
|
def test_datadog_setup_full(self, mock_datadog):
|
||||||
"""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(self.hass, datadog.DOMAIN, {
|
assert setup_component(self.hass, datadog.DOMAIN, {
|
||||||
datadog.DOMAIN: {
|
datadog.DOMAIN: {
|
||||||
|
@ -61,10 +63,11 @@ class TestDatadog(unittest.TestCase):
|
||||||
self.assertEqual(EVENT_STATE_CHANGED,
|
self.assertEqual(EVENT_STATE_CHANGED,
|
||||||
self.hass.bus.listen.call_args_list[1][0][0])
|
self.hass.bus.listen.call_args_list[1][0][0])
|
||||||
|
|
||||||
@mock.patch('datadog.initialize')
|
@MockDependency('datadog')
|
||||||
def test_datadog_setup_defaults(self, mock_connection):
|
def test_datadog_setup_defaults(self, mock_datadog):
|
||||||
"""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(self.hass, datadog.DOMAIN, {
|
assert setup_component(self.hass, datadog.DOMAIN, {
|
||||||
datadog.DOMAIN: {
|
datadog.DOMAIN: {
|
||||||
|
@ -81,10 +84,11 @@ class TestDatadog(unittest.TestCase):
|
||||||
)
|
)
|
||||||
self.assertTrue(self.hass.bus.listen.called)
|
self.assertTrue(self.hass.bus.listen.called)
|
||||||
|
|
||||||
@mock.patch('datadog.statsd')
|
@MockDependency('datadog')
|
||||||
def test_logbook_entry(self, mock_client):
|
def test_logbook_entry(self, mock_datadog):
|
||||||
"""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(self.hass, datadog.DOMAIN, {
|
assert setup_component(self.hass, datadog.DOMAIN, {
|
||||||
datadog.DOMAIN: {
|
datadog.DOMAIN: {
|
||||||
|
@ -119,10 +123,11 @@ class TestDatadog(unittest.TestCase):
|
||||||
|
|
||||||
mock_client.event.reset_mock()
|
mock_client.event.reset_mock()
|
||||||
|
|
||||||
@mock.patch('datadog.statsd')
|
@MockDependency('datadog')
|
||||||
def test_state_changed(self, mock_client):
|
def test_state_changed(self, mock_datadog):
|
||||||
"""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(self.hass, datadog.DOMAIN, {
|
assert setup_component(self.hass, datadog.DOMAIN, {
|
||||||
datadog.DOMAIN: {
|
datadog.DOMAIN: {
|
||||||
|
|
|
@ -12,6 +12,8 @@ from homeassistant.setup import setup_component
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
get_test_home_assistant, assert_setup_component, mock_service)
|
get_test_home_assistant, assert_setup_component, mock_service)
|
||||||
|
|
||||||
|
from .test_init import mutagen_mock # noqa
|
||||||
|
|
||||||
|
|
||||||
class TestTTSGooglePlatform(object):
|
class TestTTSGooglePlatform(object):
|
||||||
"""Test the Google speech component."""
|
"""Test the Google speech component."""
|
||||||
|
|
|
@ -4,6 +4,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
from unittest.mock import patch, PropertyMock
|
from unittest.mock import patch, PropertyMock
|
||||||
|
|
||||||
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
import homeassistant.components.http as http
|
import homeassistant.components.http as http
|
||||||
|
@ -19,6 +20,14 @@ from tests.common import (
|
||||||
mock_service)
|
mock_service)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def mutagen_mock():
|
||||||
|
"""Mock writing tags."""
|
||||||
|
with patch('homeassistant.components.tts.SpeechManager.write_tags',
|
||||||
|
side_effect=lambda *args: args[1]):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
class TestTTS(object):
|
class TestTTS(object):
|
||||||
"""Test the Google speech component."""
|
"""Test the Google speech component."""
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ from homeassistant.components.media_player import (
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
get_test_home_assistant, assert_setup_component, mock_service)
|
get_test_home_assistant, assert_setup_component, mock_service)
|
||||||
|
|
||||||
|
from .test_init import mutagen_mock # noqa
|
||||||
|
|
||||||
|
|
||||||
class TestTTSMaryTTSPlatform(object):
|
class TestTTSMaryTTSPlatform(object):
|
||||||
"""Test the speech component."""
|
"""Test the speech component."""
|
||||||
|
|
|
@ -11,6 +11,8 @@ from homeassistant.setup import setup_component
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
get_test_home_assistant, assert_setup_component, mock_service)
|
get_test_home_assistant, assert_setup_component, mock_service)
|
||||||
|
|
||||||
|
from .test_init import mutagen_mock # noqa
|
||||||
|
|
||||||
|
|
||||||
class TestTTSVoiceRSSPlatform(object):
|
class TestTTSVoiceRSSPlatform(object):
|
||||||
"""Test the voicerss speech component."""
|
"""Test the voicerss speech component."""
|
||||||
|
|
|
@ -10,6 +10,8 @@ from homeassistant.components.media_player import (
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
get_test_home_assistant, assert_setup_component, mock_service)
|
get_test_home_assistant, assert_setup_component, mock_service)
|
||||||
|
|
||||||
|
from .test_init import mutagen_mock # noqa
|
||||||
|
|
||||||
|
|
||||||
class TestTTSYandexPlatform(object):
|
class TestTTSYandexPlatform(object):
|
||||||
"""Test the speech component."""
|
"""Test the speech component."""
|
||||||
|
|
Loading…
Reference in New Issue