diff options
Diffstat (limited to 'functest/tests/unit/cli/commands')
-rw-r--r-- | functest/tests/unit/cli/commands/__init__.py | 0 | ||||
-rw-r--r-- | functest/tests/unit/cli/commands/test_cli_env.py | 70 | ||||
-rw-r--r-- | functest/tests/unit/cli/commands/test_cli_os.py | 80 | ||||
-rw-r--r-- | functest/tests/unit/cli/commands/test_cli_testcase.py | 81 | ||||
-rw-r--r-- | functest/tests/unit/cli/commands/test_cli_tier.py | 104 |
5 files changed, 0 insertions, 335 deletions
diff --git a/functest/tests/unit/cli/commands/__init__.py b/functest/tests/unit/cli/commands/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/functest/tests/unit/cli/commands/__init__.py +++ /dev/null diff --git a/functest/tests/unit/cli/commands/test_cli_env.py b/functest/tests/unit/cli/commands/test_cli_env.py deleted file mode 100644 index d865d3803..000000000 --- a/functest/tests/unit/cli/commands/test_cli_env.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python - -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 - -import logging -import unittest - -import mock - -from functest.cli.commands import cli_env -from functest.utils.constants import CONST -from functest.tests.unit import test_utils - - -class CliEnvTesting(unittest.TestCase): - - def setUp(self): - self.cli_environ = cli_env.CliEnv() - - def _test_show_missing_env_var(self, var, *args): - if var == 'INSTALLER_TYPE': - CONST.__setattr__('INSTALLER_TYPE', None) - reg_string = "| INSTALLER: Unknown, \S+\s*|" - elif var == 'INSTALLER_IP': - CONST.__setattr__('INSTALLER_IP', None) - reg_string = "| INSTALLER: \S+, Unknown\s*|" - elif var == 'SCENARIO': - CONST.__setattr__('DEPLOY_SCENARIO', None) - reg_string = "| SCENARIO: Unknown\s*|" - elif var == 'NODE': - CONST.__setattr__('NODE_NAME', None) - reg_string = "| POD: Unknown\s*|" - elif var == 'BUILD_TAG': - CONST.__setattr__('BUILD_TAG', None) - reg_string = "| BUILD TAG: None|" - elif var == 'DEBUG': - CONST.__setattr__('CI_DEBUG', None) - reg_string = "| DEBUG FLAG: false\s*|" - - with mock.patch('functest.cli.commands.cli_env.click.echo') \ - as mock_click_echo: - self.cli_environ.show() - mock_click_echo.assert_called_with(test_utils. - RegexMatch(reg_string)) - - def test_show_missing_ci_installer_type(self, *args): - self._test_show_missing_env_var('INSTALLER_TYPE', *args) - - def test_show_missing_ci_installer_ip(self, *args): - self._test_show_missing_env_var('INSTALLER_IP', *args) - - def test_show_missing_ci_scenario(self, *args): - self._test_show_missing_env_var('SCENARIO', *args) - - def test_show_missing_ci_node(self, *args): - self._test_show_missing_env_var('NODE', *args) - - def test_show_missing_ci_build_tag(self, *args): - self._test_show_missing_env_var('BUILD_TAG', *args) - - def test_show_missing_ci_debug(self, *args): - self._test_show_missing_env_var('DEBUG', *args) - - -if __name__ == "__main__": - logging.disable(logging.CRITICAL) - unittest.main(verbosity=2) diff --git a/functest/tests/unit/cli/commands/test_cli_os.py b/functest/tests/unit/cli/commands/test_cli_os.py deleted file mode 100644 index b827e87ca..000000000 --- a/functest/tests/unit/cli/commands/test_cli_os.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python -# -# jose.lausuch@ericsson.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# - -import logging -import unittest -import os - -import mock - -from functest.cli.commands import cli_os - - -class CliOpenStackTesting(unittest.TestCase): - - def setUp(self): - self.endpoint_ip = 'test_ip' - self.os_auth_url = 'http://test_ip:test_port/v2.0' - self.installer_type = 'test_installer_type' - self.installer_ip = 'test_installer_ip' - self.openstack_creds = 'test_openstack_creds' - self.snapshot_file = 'test_snapshot_file' - self.cli_os = cli_os.CliOpenStack() - - def test_ping_endpoint_default(self): - self.cli_os.os_auth_url = self.os_auth_url - self.cli_os.endpoint_ip = self.endpoint_ip - with mock.patch('functest.cli.commands.cli_os.os.system', - return_value=0): - self.assertEqual(self.cli_os.ping_endpoint(), 0) - - @mock.patch('functest.cli.commands.cli_os.exit', side_effect=Exception) - @mock.patch('functest.cli.commands.cli_os.click.echo') - def test_ping_endpoint_missing_auth_url(self, mock_click_echo, - mock_exit): - with self.assertRaises(Exception): - self.cli_os.os_auth_url = None - self.cli_os.ping_endpoint() - mock_click_echo.assert_called_once_with("Source the OpenStack " - "credentials first '. " - "$creds'") - - @mock.patch('functest.cli.commands.cli_os.exit') - @mock.patch('functest.cli.commands.cli_os.click.echo') - def test_ping_endpoint_os_system_fails(self, mock_click_echo, - mock_exit): - self.cli_os.os_auth_url = self.os_auth_url - self.cli_os.endpoint_ip = self.endpoint_ip - with mock.patch('functest.cli.commands.cli_os.os.system', - return_value=1): - self.cli_os.ping_endpoint() - mock_click_echo.assert_called_once_with("Cannot talk to the " - "endpoint %s\n" % - self.endpoint_ip) - mock_exit.assert_called_once_with(0) - - def test_check(self): - with mock.patch.object(self.cli_os, 'ping_endpoint'), \ - mock.patch('functest.cli.commands.cli_os.check_deployment.' - 'CheckDeployment') as mock_check_deployment: - self.cli_os.check() - self.assertTrue(mock_check_deployment.called) - - @mock.patch('functest.cli.commands.cli_os.click.echo') - def test_show_credentials(self, mock_click_echo): - key = 'OS_KEY' - value = 'OS_VALUE' - with mock.patch.dict(os.environ, {key: value}): - self.cli_os.show_credentials() - mock_click_echo.assert_any_call("{}={}".format(key, value)) - - -if __name__ == "__main__": - logging.disable(logging.CRITICAL) - unittest.main(verbosity=2) diff --git a/functest/tests/unit/cli/commands/test_cli_testcase.py b/functest/tests/unit/cli/commands/test_cli_testcase.py deleted file mode 100644 index f3648eb05..000000000 --- a/functest/tests/unit/cli/commands/test_cli_testcase.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python - -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 - - -import logging -import unittest - -import mock - -from functest.cli.commands import cli_testcase - - -class CliTestCasesTesting(unittest.TestCase): - - def setUp(self): - self.testname = 'testname' - with mock.patch('functest.cli.commands.cli_testcase.tb'): - self.cli_tests = cli_testcase.CliTestcase() - - @mock.patch('functest.cli.commands.cli_testcase.vacation.main') - def test_run_vacation(self, mock_method): - self.cli_tests.run('vacation') - self.assertTrue(mock_method.called) - - @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') - def test_run_default(self, mock_ft_utils): - cmd = "run_tests -n -r -t {}".format(self.testname) - self.cli_tests.run(self.testname, noclean=True, report=True) - mock_ft_utils.assert_called_with(cmd) - - @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') - def test_run_noclean_missing_report(self, mock_ft_utils): - cmd = "run_tests -n -t {}".format(self.testname) - self.cli_tests.run(self.testname, noclean=True, report=False) - mock_ft_utils.assert_called_with(cmd) - - @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') - def test_run_report_missing_noclean(self, mock_ft_utils): - cmd = "run_tests -r -t {}".format(self.testname) - self.cli_tests.run(self.testname, noclean=False, report=True) - mock_ft_utils.assert_called_with(cmd) - - @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') - def test_run_missing_noclean_report(self, mock_ft_utils): - cmd = "run_tests -t {}".format(self.testname) - self.cli_tests.run(self.testname, noclean=False, report=False) - mock_ft_utils.assert_called_with(cmd) - - @mock.patch('functest.cli.commands.cli_testcase.click.echo') - def test_list(self, mock_click_echo): - with mock.patch.object(self.cli_tests.tiers, 'get_tiers', - return_value=[]): - self.cli_tests.list() - mock_click_echo.assert_called_with("") - - @mock.patch('functest.cli.commands.cli_testcase.click.echo') - def test_show_default_desc_none(self, mock_click_echo): - with mock.patch.object(self.cli_tests.tiers, 'get_test', - return_value=None): - self.cli_tests.show(self.testname) - mock_click_echo.assert_any_call("The test case '%s' " - "does not exist or is" - " not supported." - % self.testname) - - @mock.patch('functest.cli.commands.cli_testcase.click.echo') - def test_show_default(self, mock_click_echo): - mock_obj = mock.Mock() - with mock.patch.object(self.cli_tests.tiers, 'get_test', - return_value=mock_obj): - self.cli_tests.show(self.testname) - mock_click_echo.assert_called_with(mock_obj) - - -if __name__ == "__main__": - logging.disable(logging.CRITICAL) - unittest.main(verbosity=2) diff --git a/functest/tests/unit/cli/commands/test_cli_tier.py b/functest/tests/unit/cli/commands/test_cli_tier.py deleted file mode 100644 index a76d12049..000000000 --- a/functest/tests/unit/cli/commands/test_cli_tier.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python - -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 - - -import logging -import unittest - -import mock - -from functest.cli.commands import cli_tier - - -class CliTierTesting(unittest.TestCase): - - def setUp(self): - self.tiername = 'tiername' - self.testnames = 'testnames' - with mock.patch('functest.cli.commands.cli_tier.tb'): - self.cli_tier = cli_tier.CliTier() - - @mock.patch('functest.cli.commands.cli_tier.click.echo') - def test_list(self, mock_click_echo): - with mock.patch.object(self.cli_tier.tiers, 'get_tiers', - return_value=[]): - self.cli_tier.list() - mock_click_echo.assert_called_with("") - - @mock.patch('functest.cli.commands.cli_tier.click.echo') - def test_show_default(self, mock_click_echo): - with mock.patch.object(self.cli_tier.tiers, 'get_tier', - return_value=self.tiername): - self.cli_tier.show(self.tiername) - mock_click_echo.assert_called_with(self.tiername) - - @mock.patch('functest.cli.commands.cli_tier.click.echo') - def test_show_missing_tier(self, mock_click_echo): - with mock.patch.object(self.cli_tier.tiers, 'get_tier', - return_value=None), \ - mock.patch.object(self.cli_tier.tiers, 'get_tier_names', - return_value='tiernames'): - self.cli_tier.show(self.tiername) - mock_click_echo.assert_called_with("The tier with name '%s' does " - "not exist. Available tiers are" - ":\n %s\n" % (self.tiername, - 'tiernames')) - - @mock.patch('functest.cli.commands.cli_tier.click.echo') - def test_gettests_default(self, mock_click_echo): - mock_obj = mock.Mock() - attrs = {'get_test_names.return_value': self.testnames} - mock_obj.configure_mock(**attrs) - - with mock.patch.object(self.cli_tier.tiers, 'get_tier', - return_value=mock_obj): - self.cli_tier.gettests(self.tiername) - mock_click_echo.assert_called_with("Test cases in tier " - "'%s':\n %s\n" % (self.tiername, - self.testnames - )) - - @mock.patch('functest.cli.commands.cli_tier.click.echo') - def test_gettests_missing_tier(self, mock_click_echo): - with mock.patch.object(self.cli_tier.tiers, 'get_tier', - return_value=None), \ - mock.patch.object(self.cli_tier.tiers, 'get_tier_names', - return_value='tiernames'): - self.cli_tier.gettests(self.tiername) - mock_click_echo.assert_called_with("The tier with name '%s' does " - "not exist. Available tiers are" - ":\n %s\n" % (self.tiername, - 'tiernames')) - - @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') - def test_run_default(self, mock_ft_utils): - cmd = "run_tests -n -r -t {}".format(self.tiername) - self.cli_tier.run(self.tiername, noclean=True, report=True) - mock_ft_utils.assert_called_with(cmd) - - @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') - def test_run_report_missing_noclean(self, mock_ft_utils): - cmd = "run_tests -r -t {}".format(self.tiername) - self.cli_tier.run(self.tiername, noclean=False, report=True) - mock_ft_utils.assert_called_with(cmd) - - @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') - def test_run_noclean_missing_report(self, mock_ft_utils): - cmd = "run_tests -n -t {}".format(self.tiername) - self.cli_tier.run(self.tiername, noclean=True, report=False) - mock_ft_utils.assert_called_with(cmd) - - @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') - def test_run_missing_noclean_report(self, mock_ft_utils): - cmd = "run_tests -t {}".format(self.tiername) - self.cli_tier.run(self.tiername, noclean=False, report=False) - mock_ft_utils.assert_called_with(cmd) - - -if __name__ == "__main__": - logging.disable(logging.CRITICAL) - unittest.main(verbosity=2) |