9ed7d82935e492e749c9e68240709584007747d6
[functest.git] / functest / tests / unit / cli / commands / test_cli_testcase.py
1 #!/usr/bin/env python
2
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
7
8 # pylint: disable=missing-docstring
9
10 import logging
11 import unittest
12
13 import mock
14
15 from functest.cli.commands import cli_testcase
16
17
18 class CliTestCasesTesting(unittest.TestCase):
19
20     def setUp(self):
21         self.testname = 'testname'
22         with mock.patch('functest.cli.commands.cli_testcase.tb'):
23             self.cli_tests = cli_testcase.CliTestcase()
24
25     @mock.patch('functest.cli.commands.cli_testcase.ft_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)
30
31     @mock.patch('functest.cli.commands.cli_testcase.ft_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)
36
37     @mock.patch('functest.cli.commands.cli_testcase.ft_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)
42
43     @mock.patch('functest.cli.commands.cli_testcase.ft_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)
48
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',
52                                return_value=[]):
53             self.cli_tests.list()
54             mock_click_echo.assert_called_with("")
55
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',
59                                return_value=None):
60             self.cli_tests.show(self.testname)
61             mock_click_echo.assert_any_call("The test case '%s' "
62                                             "does not exist or is"
63                                             " not supported."
64                                             % self.testname)
65
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)
73
74
75 if __name__ == "__main__":
76     logging.disable(logging.CRITICAL)
77     unittest.main(verbosity=2)