Log error for servicecall without required data
* Log error for services called without required attributes, in media_player, notify and thermostat platforms. * Add fan property and methods in thermostat demo component. * Add tests for notify file and thermostat demo component. * Increase coverage of tests for media_player, notify and thermostat platforms. * Fix some PEP issues, but not all. Tests still have old linting errors.
This commit is contained in:
1 parent
72fdd94b29
commit
4e4b24fcff
14 files changed
+489
-90
No files matched your search
@@ -3,8 +3,10 @@ import os
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from homeassistant import core
|
||||
import homeassistant.components.notify as notify
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
@@ -13,12 +15,27 @@ class TestCommandLine(unittest.TestCase):
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = core.HomeAssistant()
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_bad_config(self):
|
||||
"""Test set up the platform with bad/missing config."""
|
||||
self.assertFalse(notify.setup(self.hass, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'bad_platform',
|
||||
}
|
||||
}))
|
||||
self.assertFalse(notify.setup(self.hass, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'command_line',
|
||||
}
|
||||
}))
|
||||
|
||||
def test_command_line_output(self):
|
||||
"""Test the command line output."""
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
@@ -41,7 +58,7 @@ class TestCommandLine(unittest.TestCase):
|
||||
|
||||
@patch('homeassistant.components.notify.command_line._LOGGER.error')
|
||||
def test_error_for_none_zero_exit_code(self, mock_error):
|
||||
"""Test if an error if logged for non zero exit codes."""
|
||||
"""Test if an error is logged for non zero exit codes."""
|
||||
self.assertTrue(notify.setup(self.hass, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
|
||||
@@ -30,6 +30,12 @@ class TestNotifyDemo(unittest.TestCase):
|
||||
""""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_sending_none_message(self):
|
||||
"""Test send with None as message."""
|
||||
notify.send_message(self.hass, None)
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertTrue(len(self.events) == 0)
|
||||
|
||||
def test_sending_templated_message(self):
|
||||
"""Send a templated message."""
|
||||
self.hass.states.set('sensor.temperature', 10)
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
"""The tests for the notify file platform."""
|
||||
import os
|
||||
import unittest
|
||||
import tempfile
|
||||
|
||||
import homeassistant.components.notify as notify
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_TITLE_DEFAULT)
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestNotifyFile(unittest.TestCase):
|
||||
"""Test the file notify."""
|
||||
|
||||
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 down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_bad_config(self):
|
||||
"""Test set up the platform with bad/missing config."""
|
||||
self.assertFalse(notify.setup(self.hass, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'file',
|
||||
}
|
||||
}))
|
||||
|
||||
def test_notify_file(self):
|
||||
"""Test the notify file output."""
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
filename = os.path.join(tempdirname, 'notify.txt')
|
||||
message = 'one, two, testing, testing'
|
||||
self.assertTrue(notify.setup(self.hass, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'file',
|
||||
'filename': filename,
|
||||
'timestamp': 0
|
||||
}
|
||||
}))
|
||||
title = '{} notifications (Log started: {})\n{}\n'.format(
|
||||
ATTR_TITLE_DEFAULT,
|
||||
dt_util.strip_microseconds(dt_util.utcnow()),
|
||||
'-' * 80)
|
||||
|
||||
self.hass.services.call('notify', 'test', {'message': message},
|
||||
blocking=True)
|
||||
|
||||
result = open(filename).read()
|
||||
self.assertEqual(result, "{}{}\n".format(title, message))
|
||||
Reference in new issue
Block a user