mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
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:
56
tests/components/notify/test_file.py
Normal file
56
tests/components/notify/test_file.py
Normal file
@@ -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