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.os.path.isfile',
31 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
32 def test_run_missing_env_file(self, mock_click_echo, mock_os):
33 self.cli_tests.run(self.testname)
34 mock_click_echo.assert_called_with("Functest environment is not ready."
35 " Run first 'functest env prepare'")
37 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
39 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
40 def test_run_default(self, mock_ft_utils, mock_os):
41 cmd = "run_tests -n -r -t {}".format(self.testname)
42 self.cli_tests.run(self.testname, noclean=True, report=True)
43 mock_ft_utils.assert_called_with(cmd)
45 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
47 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
48 def test_run_noclean_missing_report(self, mock_ft_utils, mock_os):
49 cmd = "run_tests -n -t {}".format(self.testname)
50 self.cli_tests.run(self.testname, noclean=True, report=False)
51 mock_ft_utils.assert_called_with(cmd)
53 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
55 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
56 def test_run_report_missing_noclean(self, mock_ft_utils, mock_os):
57 cmd = "run_tests -r -t {}".format(self.testname)
58 self.cli_tests.run(self.testname, noclean=False, report=True)
59 mock_ft_utils.assert_called_with(cmd)
61 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
63 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
64 def test_run_missing_noclean_report(self, mock_ft_utils, mock_os):
65 cmd = "run_tests -t {}".format(self.testname)
66 self.cli_tests.run(self.testname, noclean=False, report=False)
67 mock_ft_utils.assert_called_with(cmd)
69 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
70 def test_list(self, mock_click_echo):
71 with mock.patch.object(self.cli_tests.tiers, 'get_tiers',
74 mock_click_echo.assert_called_with("")
76 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
77 def test_show_default_desc_none(self, mock_click_echo):
78 with mock.patch.object(self.cli_tests.tiers, 'get_test',
80 self.cli_tests.show(self.testname)
81 mock_click_echo.assert_any_call("The test case '%s' "
82 "does not exist or is"
86 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
87 def test_show_default(self, mock_click_echo):
88 mock_obj = mock.Mock()
89 with mock.patch.object(self.cli_tests.tiers, 'get_test',
90 return_value=mock_obj):
91 self.cli_tests.show(self.testname)
92 mock_click_echo.assert_called_with(mock_obj)
95 if __name__ == "__main__":
96 logging.disable(logging.CRITICAL)
97 unittest.main(verbosity=2)