Ejemplo n.º 1
0
 def test_config_not_valid_service_names(self):
     """ Test if config contains invalid service names. """
     self.assertFalse(
         shell_command.setup(
             self.hass, {
                 'shell_command': {
                     'this is invalid because space': 'touch bla.txt'
                 }
             }))
Ejemplo n.º 2
0
    def test_subprocess_raising_error(self, mock_call, mock_error):
        with tempfile.TemporaryDirectory() as tempdirname:
            path = os.path.join(tempdirname, 'called.txt')
            self.assertTrue(shell_command.setup(self.hass, {
                'shell_command': {
                    'test_service': "touch {}".format(path)
                }
            }))

            self.hass.services.call('shell_command', 'test_service',
                                    blocking=True)

            self.assertFalse(os.path.isfile(path))
            self.assertEqual(1, mock_error.call_count)
Ejemplo n.º 3
0
    def test_executing_service(self):
        """ Test if able to call a configured service. """
        with tempfile.TemporaryDirectory() as tempdirname:
            path = os.path.join(tempdirname, 'called.txt')
            self.assertTrue(shell_command.setup(self.hass, {
                'shell_command': {
                    'test_service': "date > {}".format(path)
                }
            }))

            self.hass.services.call('shell_command', 'test_service',
                                    blocking=True)

            self.assertTrue(os.path.isfile(path))
Ejemplo n.º 4
0
    def test_subprocess_raising_error(self, mock_call, mock_error):
        with tempfile.TemporaryDirectory() as tempdirname:
            path = os.path.join(tempdirname, 'called.txt')
            self.assertTrue(shell_command.setup(self.hass, {
                'shell_command': {
                    'test_service': "touch {}".format(path)
                }
            }))

            self.hass.services.call('shell_command', 'test_service',
                                    blocking=True)

            self.assertFalse(os.path.isfile(path))
            self.assertEqual(1, mock_error.call_count)
Ejemplo n.º 5
0
    def test_executing_service(self):
        """ Test if able to call a configured service. """
        with tempfile.TemporaryDirectory() as tempdirname:
            path = os.path.join(tempdirname, 'called.txt')
            self.assertTrue(shell_command.setup(self.hass, {
                'shell_command': {
                    'test_service': "date > {}".format(path)
                }
            }))

            self.hass.services.call('shell_command', 'test_service',
                                    blocking=True)

            self.assertTrue(os.path.isfile(path))
Ejemplo n.º 6
0
 def test_config_not_dict(self):
     """ Test if config is not a dict. """
     self.assertFalse(
         shell_command.setup(self.hass,
                             {'shell_command': ['some', 'weird', 'list']}))
Ejemplo n.º 7
0
 def test_config_not_valid_service_names(self):
     """ Test if config contains invalid service names. """
     self.assertFalse(shell_command.setup(self.hass, {
         'shell_command': {
             'this is invalid because space': 'touch bla.txt'
         }}))
Ejemplo n.º 8
0
 def test_config_not_dict(self):
     """ Test if config is not a dict. """
     self.assertFalse(shell_command.setup(self.hass, {
         'shell_command': ['some', 'weird', 'list']
         }))