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_notify_file(self, mock_utcnow): """Test the notify file output.""" mock_utcnow.return_value = dt_util.as_utc(dt_util.now()) 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.utcnow().isoformat(), '-' * 80) self.hass.services.call('notify', 'test', {'message': message}, blocking=True) result = open(filename).read() self.assertEqual(result, "{}{}\n".format(title, message))
def test_notify_file(self, mock_utcnow): """Test the notify file output.""" mock_utcnow.return_value = dt_util.as_utc(dt_util.now()) 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.utcnow().isoformat(), '-' * 80) self.hass.services.call('notify', 'test', {'message': message}, blocking=True) result = open(filename).read() self.assertEqual(result, "{}{}\n".format(title, message))
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_error_for_none_zero_exit_code(self, mock_error): """Test if an error is logged for non zero exit codes.""" self.assertTrue(notify.setup(self.hass, { 'notify': { 'name': 'test', 'platform': 'command_line', 'command': 'echo $(cat); exit 1' } })) self.hass.services.call('notify', 'test', {'message': 'error'}, blocking=True) self.assertEqual(1, mock_error.call_count)
def setUp(self): # pylint: disable=invalid-name """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() self.assertTrue( notify.setup(self.hass, {'notify': { 'platform': 'demo' }})) self.events = [] def record_event(event): """Record event to send notification.""" self.events.append(event) self.hass.bus.listen(demo.EVENT_NOTIFY, record_event)
def setUp(self): # pylint: disable=invalid-name """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() self.assertTrue(notify.setup(self.hass, { 'notify': { 'platform': 'demo' } })) self.events = [] def record_event(event): """Record event to send notification.""" self.events.append(event) self.hass.bus.listen(demo.EVENT_NOTIFY, record_event)
def test_command_line_output(self): """Test the command line output.""" with tempfile.TemporaryDirectory() as tempdirname: filename = os.path.join(tempdirname, 'message.txt') message = 'one, two, testing, testing' self.assertTrue(notify.setup(self.hass, { 'notify': { 'name': 'test', 'platform': 'command_line', 'command': 'echo $(cat) > {}'.format(filename) } })) self.hass.services.call('notify', 'test', {'message': message}, blocking=True) result = open(filename).read() # the echo command adds a line break self.assertEqual(result, "{}\n".format(message))