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
8 # pylint: disable=missing-docstring
15 from functest.cli.commands import cli_testcase
18 class CliTestCasesTesting(unittest.TestCase):
21 self.testname = 'testname'
22 with mock.patch('functest.ci.tier_builder'):
23 self.cli_tests = cli_testcase.CliTestcase()
25 @mock.patch('functest.utils.functest_utils.execute_command')
26 def test_run_default(self, mock_ft_utils):
27 cmd = "run_tests -n -r -t {}".format(self.testname)
28 self.cli_tests.run(self.testname, noclean=True, report=True)
29 mock_ft_utils.assert_called_with(cmd)
31 @mock.patch('functest.utils.functest_utils.execute_command')
32 def test_run_noclean_missing_report(self, mock_ft_utils):
33 cmd = "run_tests -n -t {}".format(self.testname)
34 self.cli_tests.run(self.testname, noclean=True, report=False)
35 mock_ft_utils.assert_called_with(cmd)
37 @mock.patch('functest.utils.functest_utils.execute_command')
38 def test_run_report_missing_noclean(self, mock_ft_utils):
39 cmd = "run_tests -r -t {}".format(self.testname)
40 self.cli_tests.run(self.testname, noclean=False, report=True)
41 mock_ft_utils.assert_called_with(cmd)
43 @mock.patch('functest.utils.functest_utils.execute_command')
44 def test_run_missing_noclean_report(self, mock_ft_utils):
45 cmd = "run_tests -t {}".format(self.testname)
46 self.cli_tests.run(self.testname, noclean=False, report=False)
47 mock_ft_utils.assert_called_with(cmd)
49 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
50 def test_list(self, mock_click_echo):
51 with mock.patch.object(self.cli_tests.tiers, 'get_tiers',
54 mock_click_echo.assert_called_with("")
56 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
57 def test_show_default_desc_none(self, mock_click_echo):
58 with mock.patch.object(self.cli_tests.tiers, 'get_test',
60 self.cli_tests.show(self.testname)
61 mock_click_echo.assert_any_call("The test case '%s' "
62 "does not exist or is"
66 @mock.patch('functest.cli.commands.cli_testcase.click.echo')
67 def test_show_default(self, mock_click_echo):
68 mock_obj = mock.Mock()
69 with mock.patch.object(self.cli_tests.tiers, 'get_test',
70 return_value=mock_obj):
71 self.cli_tests.show(self.testname)
72 mock_click_echo.assert_called_with(mock_obj)
75 if __name__ == "__main__":
76 logging.disable(logging.CRITICAL)
77 unittest.main(verbosity=2)