3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # pylint: disable=missing-docstring
15 from functest.cli.commands import cli_testcase
18 class CliTestCasesTesting(unittest.TestCase):
21 self.testname = 'testname'
22 with mock.patch('functest.cli.commands.cli_testcase.tb'):
23 self.cli_tests = cli_testcase.CliTestcase()
25 @mock.patch('functest.cli.commands.cli_testcase.vacation.main')
26 def test_run_vacation(self, mock_method):
27 self.cli_tests.run('vacation')
28 self.assertTrue(mock_method.called)
30 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
31 def test_run_default(self, mock_ft_utils):
32 cmd = "run_tests -n -r -t {}".format(self.testname)
33 self.cli_tests.run(self.testname, noclean=True, report=True)
34 mock_ft_utils.assert_called_with(cmd)
36 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
37 def test_run_noclean_missing_report(self, mock_ft_utils):
38 cmd = "run_tests -n -t {}".format(self.testname)
39 self.cli_tests.run(self.testname, noclean=True, report=False)
40 mock_ft_utils.assert_called_with(cmd)
42 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
43 def test_run_report_missing_noclean(self, mock_ft_utils):
44 cmd = "run_tests -r -t {}".format(self.testname)
45 self.cli_tests.run(self.testname, noclean=False, report=True)
46 mock_ft_utils.assert_called_with(cmd)
48 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
49 def test_run_missing_noclean_report(self, mock_ft_utils):
50 cmd = "run_tests -t {}".format(self.testname)
51 self.cli_tests.run(self.testname, noclean=False, report=False)
52 mock_ft_utils.assert_called_with(cmd)
54 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
55 def test_list(self, mock_click_echo):
56 with mock.patch.object(self.cli_tests.tiers, 'get_tiers',
59 mock_click_echo.assert_called_with("")
61 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
62 def test_show_default_desc_none(self, mock_click_echo):
63 with mock.patch.object(self.cli_tests.tiers, 'get_test',
65 self.cli_tests.show(self.testname)
66 mock_click_echo.assert_any_call("The test case '%s' "
67 "does not exist or is"
71 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
72 def test_show_default(self, mock_click_echo):
73 mock_obj = mock.Mock()
74 with mock.patch.object(self.cli_tests.tiers, 'get_test',
75 return_value=mock_obj):
76 self.cli_tests.show(self.testname)
77 mock_click_echo.assert_called_with(mock_obj)
80 if __name__ == "__main__":
81 logging.disable(logging.CRITICAL)
82 unittest.main(verbosity=2)