Remove prepare_env
[functest.git] / functest / tests / unit / cli / commands / test_cli_env.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 import logging
9 import unittest
10
11 import mock
12
13 from functest.cli.commands import cli_env
14 from functest.utils.constants import CONST
15 from functest.tests.unit import test_utils
16
17
18 class CliEnvTesting(unittest.TestCase):
19
20     def setUp(self):
21         self.cli_environ = cli_env.CliEnv()
22
23     def _test_show_missing_env_var(self, var, *args):
24         if var == 'INSTALLER_TYPE':
25             CONST.__setattr__('INSTALLER_TYPE', None)
26             reg_string = "|  INSTALLER: Unknown, \S+\s*|"
27         elif var == 'INSTALLER_IP':
28             CONST.__setattr__('INSTALLER_IP', None)
29             reg_string = "|  INSTALLER: \S+, Unknown\s*|"
30         elif var == 'SCENARIO':
31             CONST.__setattr__('DEPLOY_SCENARIO', None)
32             reg_string = "|   SCENARIO: Unknown\s*|"
33         elif var == 'NODE':
34             CONST.__setattr__('NODE_NAME', None)
35             reg_string = "|        POD: Unknown\s*|"
36         elif var == 'BUILD_TAG':
37             CONST.__setattr__('BUILD_TAG', None)
38             reg_string = "|  BUILD TAG: None|"
39         elif var == 'DEBUG':
40             CONST.__setattr__('CI_DEBUG', None)
41             reg_string = "| DEBUG FLAG: false\s*|"
42
43         with mock.patch('functest.cli.commands.cli_env.click.echo') \
44                 as mock_click_echo:
45             self.cli_environ.show()
46             mock_click_echo.assert_called_with(test_utils.
47                                                RegexMatch(reg_string))
48
49     def test_show_missing_ci_installer_type(self, *args):
50         self._test_show_missing_env_var('INSTALLER_TYPE', *args)
51
52     def test_show_missing_ci_installer_ip(self, *args):
53         self._test_show_missing_env_var('INSTALLER_IP', *args)
54
55     def test_show_missing_ci_scenario(self, *args):
56         self._test_show_missing_env_var('SCENARIO', *args)
57
58     def test_show_missing_ci_node(self, *args):
59         self._test_show_missing_env_var('NODE', *args)
60
61     def test_show_missing_ci_build_tag(self, *args):
62         self._test_show_missing_env_var('BUILD_TAG', *args)
63
64     def test_show_missing_ci_debug(self, *args):
65         self._test_show_missing_env_var('DEBUG', *args)
66
67
68 if __name__ == "__main__":
69     logging.disable(logging.CRITICAL)
70     unittest.main(verbosity=2)