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):
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.os.path.isfile',
32 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
33 def test_run_missing_env_file(self, mock_click_echo, mock_os):
34 self.cli_tests.run(self.testname)
35 mock_click_echo.assert_called_with("Functest environment is not ready."
36 " Run first 'functest env prepare'")
38 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
40 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
41 def test_run_default(self, mock_ft_utils, mock_os):
42 cmd = ("python %s/functest/ci/run_tests.py "
44 (CONST.__getattribute__('dir_repo_functest'),
45 "-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 "
55 (CONST.__getattribute__('dir_repo_functest'),
56 "-n ", self.testname))
57 self.cli_tests.run(self.testname, noclean=True, report=False)
58 mock_ft_utils.assert_called_with(cmd)
60 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
62 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
63 def test_run_report_missing_noclean(self, mock_ft_utils, mock_os):
64 cmd = ("python %s/functest/ci/run_tests.py "
66 (CONST.__getattribute__('dir_repo_functest'),
67 "-r ", self.testname))
68 self.cli_tests.run(self.testname, noclean=False, report=True)
69 mock_ft_utils.assert_called_with(cmd)
71 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
73 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
74 def test_run_missing_noclean_report(self, mock_ft_utils, mock_os):
75 cmd = ("python %s/functest/ci/run_tests.py "
77 (CONST.__getattribute__('dir_repo_functest'),
79 self.cli_tests.run(self.testname, noclean=False, report=False)
80 mock_ft_utils.assert_called_with(cmd)
82 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
83 def test_list(self, mock_click_echo):
84 with mock.patch.object(self.cli_tests.tiers, 'get_tiers',
87 mock_click_echo.assert_called_with("")
89 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
90 def test_show_default_desc_none(self, mock_click_echo):
91 with mock.patch.object(self.cli_tests.tiers, 'get_test',
93 self.cli_tests.show(self.testname)
94 mock_click_echo.assert_any_call("The test case '%s' "
95 "does not exist or is"
99 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
100 def test_show_default(self, mock_click_echo):
101 mock_obj = mock.Mock()
102 with mock.patch.object(self.cli_tests.tiers, 'get_test',
103 return_value=mock_obj):
104 self.cli_tests.show(self.testname)
105 mock_click_echo.assert_called_with(mock_obj)
108 if __name__ == "__main__":
109 logging.disable(logging.CRITICAL)
110 unittest.main(verbosity=2)