f3648eb0505facb471c42266dfe71d87aafc7b6a
[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
9 import logging
10 import unittest
11
12 import mock
13
14 from functest.cli.commands import cli_testcase
15
16
17 class CliTestCasesTesting(unittest.TestCase):
18
19     def setUp(self):
20         self.testname = 'testname'
21         with mock.patch('functest.cli.commands.cli_testcase.tb'):
22             self.cli_tests = cli_testcase.CliTestcase()
23
24     @mock.patch('functest.cli.commands.cli_testcase.vacation.main')
25     def test_run_vacation(self, mock_method):
26         self.cli_tests.run('vacation')
27         self.assertTrue(mock_method.called)
28
29     @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
30     def test_run_default(self, mock_ft_utils):
31         cmd = "run_tests -n -r -t {}".format(self.testname)
32         self.cli_tests.run(self.testname, noclean=True, report=True)
33         mock_ft_utils.assert_called_with(cmd)
34
35     @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
36     def test_run_noclean_missing_report(self, mock_ft_utils):
37         cmd = "run_tests -n -t {}".format(self.testname)
38         self.cli_tests.run(self.testname, noclean=True, report=False)
39         mock_ft_utils.assert_called_with(cmd)
40
41     @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
42     def test_run_report_missing_noclean(self, mock_ft_utils):
43         cmd = "run_tests -r -t {}".format(self.testname)
44         self.cli_tests.run(self.testname, noclean=False, report=True)
45         mock_ft_utils.assert_called_with(cmd)
46
47     @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
48     def test_run_missing_noclean_report(self, mock_ft_utils):
49         cmd = "run_tests -t {}".format(self.testname)
50         self.cli_tests.run(self.testname, noclean=False, report=False)
51         mock_ft_utils.assert_called_with(cmd)
52
53     @mock.patch('functest.cli.commands.cli_testcase.click.echo')
54     def test_list(self, mock_click_echo):
55         with mock.patch.object(self.cli_tests.tiers, 'get_tiers',
56                                return_value=[]):
57             self.cli_tests.list()
58             mock_click_echo.assert_called_with("")
59
60     @mock.patch('functest.cli.commands.cli_testcase.click.echo')
61     def test_show_default_desc_none(self, mock_click_echo):
62         with mock.patch.object(self.cli_tests.tiers, 'get_test',
63                                return_value=None):
64             self.cli_tests.show(self.testname)
65             mock_click_echo.assert_any_call("The test case '%s' "
66                                             "does not exist or is"
67                                             " not supported."
68                                             % self.testname)
69
70     @mock.patch('functest.cli.commands.cli_testcase.click.echo')
71     def test_show_default(self, mock_click_echo):
72         mock_obj = mock.Mock()
73         with mock.patch.object(self.cli_tests.tiers, 'get_test',
74                                return_value=mock_obj):
75             self.cli_tests.show(self.testname)
76             mock_click_echo.assert_called_with(mock_obj)
77
78
79 if __name__ == "__main__":
80     logging.disable(logging.CRITICAL)
81     unittest.main(verbosity=2)