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
15 from functest.utils.constants import CONST
18 class CliTestCasesTesting(unittest.TestCase):
20 logging.disable(logging.CRITICAL)
23 self.testname = 'testname'
24 with mock.patch('functest.cli.commands.cli_testcase.tb'):
25 self.cli_tests = cli_testcase.CliTestcase()
27 @mock.patch('functest.cli.commands.cli_testcase.vacation.main')
28 def test_run_vacation(self, mock_method):
29 self.cli_tests.run('vacation')
30 self.assertTrue(mock_method.called)
32 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
34 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
35 def test_run_missing_env_file(self, mock_click_echo, mock_os):
36 self.cli_tests.run(self.testname)
37 mock_click_echo.assert_called_with("Functest environment is not ready."
38 " Run first 'functest env prepare'")
40 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
42 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
43 def test_run_default(self, mock_ft_utils, mock_os):
44 cmd = ("python %s/functest/ci/run_tests.py "
45 "%s -t %s" % (CONST.dir_repo_functest, "-n -r ", self.testname))
46 self.cli_tests.run(self.testname, noclean=True, report=True)
47 mock_ft_utils.assert_called_with(cmd)
49 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
51 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
52 def test_run_noclean_missing_report(self, mock_ft_utils, mock_os):
53 cmd = ("python %s/functest/ci/run_tests.py "
54 "%s -t %s" % (CONST.dir_repo_functest, "-n ", self.testname))
55 self.cli_tests.run(self.testname, noclean=True, report=False)
56 mock_ft_utils.assert_called_with(cmd)
58 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
60 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
61 def test_run_report_missing_noclean(self, mock_ft_utils, mock_os):
62 cmd = ("python %s/functest/ci/run_tests.py "
63 "%s -t %s" % (CONST.dir_repo_functest, "-r ", self.testname))
64 self.cli_tests.run(self.testname, noclean=False, report=True)
65 mock_ft_utils.assert_called_with(cmd)
67 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
69 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
70 def test_run_missing_noclean_report(self, mock_ft_utils, mock_os):
71 cmd = ("python %s/functest/ci/run_tests.py "
72 "%s -t %s" % (CONST.dir_repo_functest, "", self.testname))
73 self.cli_tests.run(self.testname, noclean=False, report=False)
74 mock_ft_utils.assert_called_with(cmd)
76 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
77 def test_list(self, mock_click_echo):
78 with mock.patch.object(self.cli_tests.tiers, 'get_tiers',
81 mock_click_echo.assert_called_with("")
83 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
84 def test_show_default_desc_none(self, mock_click_echo):
85 with mock.patch.object(self.cli_tests.tiers, 'get_test',
87 self.cli_tests.show(self.testname)
88 mock_click_echo.assert_any_call("The test case '%s' "
89 "does not exist or is"
93 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
94 def test_show_default(self, mock_click_echo):
95 mock_obj = mock.Mock()
96 with mock.patch.object(self.cli_tests.tiers, 'get_test',
97 return_value=mock_obj):
98 self.cli_tests.show(self.testname)
99 mock_click_echo.assert_called_with(mock_obj)
102 if __name__ == "__main__":
103 unittest.main(verbosity=2)