Switch to check_deployment instead of check_os.sh
[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.os.path.isfile',
30                 return_value=False)
31     @mock.patch('functest.cli.commands.cli_testcase.click.echo')
32     def test_run_missing_env_file(self, mock_click_echo, mock_os):
33         self.cli_tests.run(self.testname)
34         mock_click_echo.assert_called_with("Functest environment is not ready."
35                                            " Run first 'functest env prepare'")
36
37     @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
38                 return_value=True)
39     @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
40     def test_run_default(self, mock_ft_utils, mock_os):
41         cmd = "run_tests -n -r -t {}".format(self.testname)
42         self.cli_tests.run(self.testname, noclean=True, report=True)
43         mock_ft_utils.assert_called_with(cmd)
44
45     @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
46                 return_value=True)
47     @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
48     def test_run_noclean_missing_report(self, mock_ft_utils, mock_os):
49         cmd = "run_tests -n -t {}".format(self.testname)
50         self.cli_tests.run(self.testname, noclean=True, report=False)
51         mock_ft_utils.assert_called_with(cmd)
52
53     @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
54                 return_value=True)
55     @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
56     def test_run_report_missing_noclean(self, mock_ft_utils, mock_os):
57         cmd = "run_tests -r -t {}".format(self.testname)
58         self.cli_tests.run(self.testname, noclean=False, report=True)
59         mock_ft_utils.assert_called_with(cmd)
60
61     @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
62                 return_value=True)
63     @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
64     def test_run_missing_noclean_report(self, mock_ft_utils, mock_os):
65         cmd = "run_tests -t {}".format(self.testname)
66         self.cli_tests.run(self.testname, noclean=False, report=False)
67         mock_ft_utils.assert_called_with(cmd)
68
69     @mock.patch('functest.cli.commands.cli_testcase.click.echo')
70     def test_list(self, mock_click_echo):
71         with mock.patch.object(self.cli_tests.tiers, 'get_tiers',
72                                return_value=[]):
73             self.cli_tests.list()
74             mock_click_echo.assert_called_with("")
75
76     @mock.patch('functest.cli.commands.cli_testcase.click.echo')
77     def test_show_default_desc_none(self, mock_click_echo):
78         with mock.patch.object(self.cli_tests.tiers, 'get_test',
79                                return_value=None):
80             self.cli_tests.show(self.testname)
81             mock_click_echo.assert_any_call("The test case '%s' "
82                                             "does not exist or is"
83                                             " not supported."
84                                             % self.testname)
85
86     @mock.patch('functest.cli.commands.cli_testcase.click.echo')
87     def test_show_default(self, mock_click_echo):
88         mock_obj = mock.Mock()
89         with mock.patch.object(self.cli_tests.tiers, 'get_test',
90                                return_value=mock_obj):
91             self.cli_tests.show(self.testname)
92             mock_click_echo.assert_called_with(mock_obj)
93
94
95 if __name__ == "__main__":
96     logging.disable(logging.CRITICAL)
97     unittest.main(verbosity=2)