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
14 from functest.cli.commands import cli_testcase
17 class CliTestCasesTesting(unittest.TestCase):
20 self.testname = 'testname'
21 with mock.patch('functest.cli.commands.cli_testcase.tb'):
22 self.cli_tests = cli_testcase.CliTestcase()
24 @mock.patch('functest.cli.commands.cli_testcase.vacation.main')
25 def test_run_vacation(self, mock_method):
26 self.cli_tests.run('vacation')
27 self.assertTrue(mock_method.called)
29 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
30 def test_run_default(self, mock_ft_utils):
31 cmd = "run_tests -n -r -t {}".format(self.testname)
32 self.cli_tests.run(self.testname, noclean=True, report=True)
33 mock_ft_utils.assert_called_with(cmd)
35 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
36 def test_run_noclean_missing_report(self, mock_ft_utils):
37 cmd = "run_tests -n -t {}".format(self.testname)
38 self.cli_tests.run(self.testname, noclean=True, report=False)
39 mock_ft_utils.assert_called_with(cmd)
41 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
42 def test_run_report_missing_noclean(self, mock_ft_utils):
43 cmd = "run_tests -r -t {}".format(self.testname)
44 self.cli_tests.run(self.testname, noclean=False, report=True)
45 mock_ft_utils.assert_called_with(cmd)
47 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
48 def test_run_missing_noclean_report(self, mock_ft_utils):
49 cmd = "run_tests -t {}".format(self.testname)
50 self.cli_tests.run(self.testname, noclean=False, report=False)
51 mock_ft_utils.assert_called_with(cmd)
53 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
54 def test_list(self, mock_click_echo):
55 with mock.patch.object(self.cli_tests.tiers, 'get_tiers',
58 mock_click_echo.assert_called_with("")
60 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
61 def test_show_default_desc_none(self, mock_click_echo):
62 with mock.patch.object(self.cli_tests.tiers, 'get_test',
64 self.cli_tests.show(self.testname)
65 mock_click_echo.assert_any_call("The test case '%s' "
66 "does not exist or is"
70 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
71 def test_show_default(self, mock_click_echo):
72 mock_obj = mock.Mock()
73 with mock.patch.object(self.cli_tests.tiers, 'get_test',
74 return_value=mock_obj):
75 self.cli_tests.show(self.testname)
76 mock_click_echo.assert_called_with(mock_obj)
79 if __name__ == "__main__":
80 logging.disable(logging.CRITICAL)
81 unittest.main(verbosity=2)