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 "
46 (CONST.__getattribute__('dir_repo_functest'),
47 "-n -r ", self.testname))
48 self.cli_tests.run(self.testname, noclean=True, report=True)
49 mock_ft_utils.assert_called_with(cmd)
51 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
53 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
54 def test_run_noclean_missing_report(self, mock_ft_utils, mock_os):
55 cmd = ("python %s/functest/ci/run_tests.py "
57 (CONST.__getattribute__('dir_repo_functest'),
58 "-n ", self.testname))
59 self.cli_tests.run(self.testname, noclean=True, report=False)
60 mock_ft_utils.assert_called_with(cmd)
62 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
64 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
65 def test_run_report_missing_noclean(self, mock_ft_utils, mock_os):
66 cmd = ("python %s/functest/ci/run_tests.py "
68 (CONST.__getattribute__('dir_repo_functest'),
69 "-r ", self.testname))
70 self.cli_tests.run(self.testname, noclean=False, report=True)
71 mock_ft_utils.assert_called_with(cmd)
73 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
75 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
76 def test_run_missing_noclean_report(self, mock_ft_utils, mock_os):
77 cmd = ("python %s/functest/ci/run_tests.py "
79 (CONST.__getattribute__('dir_repo_functest'),
81 self.cli_tests.run(self.testname, noclean=False, report=False)
82 mock_ft_utils.assert_called_with(cmd)
84 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
85 def test_list(self, mock_click_echo):
86 with mock.patch.object(self.cli_tests.tiers, 'get_tiers',
89 mock_click_echo.assert_called_with("")
91 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
92 def test_show_default_desc_none(self, mock_click_echo):
93 with mock.patch.object(self.cli_tests.tiers, 'get_test',
95 self.cli_tests.show(self.testname)
96 mock_click_echo.assert_any_call("The test case '%s' "
97 "does not exist or is"
101 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
102 def test_show_default(self, mock_click_echo):
103 mock_obj = mock.Mock()
104 with mock.patch.object(self.cli_tests.tiers, 'get_test',
105 return_value=mock_obj):
106 self.cli_tests.show(self.testname)
107 mock_click_echo.assert_called_with(mock_obj)
110 if __name__ == "__main__":
111 unittest.main(verbosity=2)