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 "
43 "%s -t %s" % (CONST.dir_repo_functest, "-n -r ", self.testname))
44 self.cli_tests.run(self.testname, noclean=True, report=True)
45 mock_ft_utils.assert_called_with(cmd)
47 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
49 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
50 def test_run_noclean_missing_report(self, mock_ft_utils, mock_os):
51 cmd = ("python %s/functest/ci/run_tests.py "
52 "%s -t %s" % (CONST.dir_repo_functest, "-n ", self.testname))
53 self.cli_tests.run(self.testname, noclean=True, report=False)
54 mock_ft_utils.assert_called_with(cmd)
56 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
58 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
59 def test_run_report_missing_noclean(self, mock_ft_utils, mock_os):
60 cmd = ("python %s/functest/ci/run_tests.py "
61 "%s -t %s" % (CONST.dir_repo_functest, "-r ", self.testname))
62 self.cli_tests.run(self.testname, noclean=False, report=True)
63 mock_ft_utils.assert_called_with(cmd)
65 @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
67 @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
68 def test_run_missing_noclean_report(self, mock_ft_utils, mock_os):
69 cmd = ("python %s/functest/ci/run_tests.py "
70 "%s -t %s" % (CONST.dir_repo_functest, "", self.testname))
71 self.cli_tests.run(self.testname, noclean=False, report=False)
72 mock_ft_utils.assert_called_with(cmd)
74 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
75 def test_list(self, mock_click_echo):
76 with mock.patch.object(self.cli_tests.tiers, 'get_tiers',
79 mock_click_echo.assert_called_with("")
81 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
82 def test_show_default_desc_none(self, mock_click_echo):
83 with mock.patch.object(self.cli_tests.tiers, 'get_test',
85 self.cli_tests.show(self.testname)
86 mock_click_echo.assert_any_call("The test case '%s' "
87 "does not exist or is"
91 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
92 def test_show_default(self, mock_click_echo):
93 mock_obj = mock.Mock()
94 with mock.patch.object(self.cli_tests.tiers, 'get_test',
95 return_value=mock_obj):
96 self.cli_tests.show(self.testname)
97 mock_click_echo.assert_called_with(mock_obj)
100 if __name__ == "__main__":
101 logging.disable(logging.CRITICAL)
102 unittest.main(verbosity=2)