コード例 #1
0
    def test_get_shell_cmds_funcs_with_params(self):
        self.service.config = {
            'generic_command_config': {
                'shell_commands': [
                    {
                        'name': 'test_1',
                        'command': 'echo {} {}',
                        'allow_params': True
                    },
                ]
            }
        }
        params = {
            "shell_params": ["Hello", "world!"]
        }

        table = get_shell_commands_from_config(self.service.config)
        func_1 = table['test_1']
        result_1 = asyncio.get_event_loop().run_until_complete(
            func_1(params)
        )

        self.assertEqual(
            result_1,
            {'stdout': 'Hello world!\n', 'stderr': '', 'returncode': 0}
        )
        pass
コード例 #2
0
    def test_get_shell_cmds_funcs(self):
        self.service.config = {
            'generic_command_config': {
                'shell_commands': [
                    {
                        'name': 'test_1',
                        'command': 'echo'
                    },
                ],
            },
        }

        table = get_shell_commands_from_config(self.service.config)
        func_1 = table['test_1']
        result_1 = asyncio.get_event_loop().run_until_complete(
            func_1(mock.Mock()), )

        self.assertEqual(
            result_1,
            {
                'stdout': '\n',
                'stderr': '',
                'returncode': 0
            },
        )
コード例 #3
0
 def test_get_shell_cmds_missing_fields(self):
     self.service.config = {
         'generic_command_config': {
             'shell_commands': [
                 {'name': 'test_1'},
                 {'command': '/bin/false'},
             ]
         }
     }
     table = get_shell_commands_from_config(self.service.config)
     self.assertEqual(table, {})
コード例 #4
0
 def test_get_shell_cmds(self):
     self.service.config = {
         'generic_command_config': {
             'shell_commands': [
                 {'name': 'test_1', 'command': '/bin/true'},
                 {'name': 'test_2', 'command': '/bin/false'},
             ]
         }
     }
     table = get_shell_commands_from_config(self.service.config)
     self.assertIn('test_1', table)
     self.assertIn('test_2', table)
コード例 #5
0
    def test_get_shell_cmds_nonexistent_func(self):
        self.service.config = {
            'generic_command_config': {
                'shell_commands': [
                    {'name': 'test_1', 'command': 'nonexistent/command foo'},
                ]
            }
        }

        table = get_shell_commands_from_config(self.service.config)
        func_1 = table['test_1']
        try:
            asyncio.get_event_loop().run_until_complete(
                func_1(mock.Mock())
            )
            self.fail('An exception should have been raised')
        except FileNotFoundError:
            pass
コード例 #6
0
 def test_get_shell_cmds_missing_shell_commands_list(self):
     self.service.config = {'generic_command_config': {}}
     table = get_shell_commands_from_config(self.service.config)
     self.assertEqual(table, {})
コード例 #7
0
 def test_get_shell_cmds_missing_config(self):
     self.service.config = {}
     table = get_shell_commands_from_config(self.service.config)
     self.assertEqual(table, {})