diff options
Diffstat (limited to 'functest/tests/unit/cli')
-rw-r--r-- | functest/tests/unit/cli/commands/test_cli_env.py | 23 | ||||
-rw-r--r-- | functest/tests/unit/cli/commands/test_cli_os.py | 84 | ||||
-rw-r--r-- | functest/tests/unit/cli/commands/test_cli_testcase.py | 26 | ||||
-rw-r--r-- | functest/tests/unit/cli/commands/test_cli_tier.py | 26 | ||||
-rw-r--r-- | functest/tests/unit/cli/test_cli_base.py | 7 |
5 files changed, 35 insertions, 131 deletions
diff --git a/functest/tests/unit/cli/commands/test_cli_env.py b/functest/tests/unit/cli/commands/test_cli_env.py index 14e926eb..0b18554b 100644 --- a/functest/tests/unit/cli/commands/test_cli_env.py +++ b/functest/tests/unit/cli/commands/test_cli_env.py @@ -6,9 +6,9 @@ # http://www.apache.org/licenses/LICENSE-2.0 import logging +import pkg_resources import unittest -from git.exc import NoSuchPathError import mock from functest.cli.commands import cli_env @@ -25,8 +25,8 @@ class CliEnvTesting(unittest.TestCase): return_value=False) @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') def test_prepare_default(self, mock_ft_utils, mock_os): - cmd = ("python %s/functest/ci/prepare_env.py start" % - CONST.__getattribute__('dir_repo_functest')) + cmd = ("python %s start" % pkg_resources.resource_filename( + 'functest', 'ci/prepare_env.py')) self.cli_environ.prepare() mock_ft_utils.assert_called_with(cmd) @@ -37,8 +37,8 @@ class CliEnvTesting(unittest.TestCase): with mock.patch('__builtin__.raw_input', return_value="y"), \ mock.patch('functest.cli.commands.cli_testcase.os.remove') \ as mock_os_remove: - cmd = ("python %s/functest/ci/prepare_env.py start" % - CONST.__getattribute__('dir_repo_functest')) + cmd = ("python %s start" % pkg_resources.resource_filename( + 'functest', 'ci/prepare_env.py')) self.cli_environ.prepare() mock_os_remove.assert_called_once_with( CONST.__getattribute__('env_active')) @@ -72,42 +72,29 @@ class CliEnvTesting(unittest.TestCase): mock_click_echo.assert_called_with(test_utils. RegexMatch(reg_string)) - @mock.patch('functest.cli.commands.cli_env.git.Repo') def test_show_missing_ci_installer_type(self, *args): self._test_show_missing_env_var('INSTALLER_TYPE', *args) - @mock.patch('functest.cli.commands.cli_env.git.Repo') def test_show_missing_ci_installer_ip(self, *args): self._test_show_missing_env_var('INSTALLER_IP', *args) - @mock.patch('functest.cli.commands.cli_env.git.Repo') def test_show_missing_ci_scenario(self, *args): self._test_show_missing_env_var('SCENARIO', *args) - @mock.patch('functest.cli.commands.cli_env.git.Repo') def test_show_missing_ci_node(self, *args): self._test_show_missing_env_var('NODE', *args) - @mock.patch('functest.cli.commands.cli_env.git.Repo') def test_show_missing_ci_build_tag(self, *args): self._test_show_missing_env_var('BUILD_TAG', *args) - @mock.patch('functest.cli.commands.cli_env.git.Repo') def test_show_missing_ci_debug(self, *args): self._test_show_missing_env_var('DEBUG', *args) - @mock.patch('functest.cli.commands.cli_env.git.Repo') @mock.patch('functest.cli.commands.cli_env.os.path.isfile', return_value=False) def test_show_missing_environment(self, *args): self._test_show_missing_env_var('STATUS', *args) - @mock.patch('functest.cli.commands.cli_env.os.path.exists', - return_value=False) - def test_show_missing_git_repo_dir(self, *args): - CONST.__setattr__('dir_repo_functest', None) - self.assertRaises(NoSuchPathError, lambda: self.cli_environ.show()) - @mock.patch('functest.cli.commands.cli_env.click.echo') @mock.patch('functest.cli.commands.cli_env.os.path.isfile', return_value=True) diff --git a/functest/tests/unit/cli/commands/test_cli_os.py b/functest/tests/unit/cli/commands/test_cli_os.py index b551ee4d..50ebe4b5 100644 --- a/functest/tests/unit/cli/commands/test_cli_os.py +++ b/functest/tests/unit/cli/commands/test_cli_os.py @@ -8,13 +8,13 @@ # import logging +import pkg_resources import unittest import os import mock from functest.cli.commands import cli_os -from functest.utils.constants import CONST class CliOpenStackTesting(unittest.TestCase): @@ -25,7 +25,6 @@ class CliOpenStackTesting(unittest.TestCase): self.installer_type = 'test_installer_type' self.installer_ip = 'test_installer_ip' self.openstack_creds = 'test_openstack_creds' - self.dir_repo_functest = 'test_dir_repo_functest' self.snapshot_file = 'test_snapshot_file' self.cli_os = cli_os.CliOpenStack() @@ -62,87 +61,12 @@ class CliOpenStackTesting(unittest.TestCase): mock_exit.assert_called_once_with(0) @mock.patch('functest.cli.commands.cli_os.ft_utils.execute_command') - @mock.patch('functest.cli.commands.cli_os.os.path.isfile', - return_value=False) - @mock.patch('functest.cli.commands.cli_os.click.echo') - def test_fetch_credentials_default(self, mock_click_echo, - mock_os_path, - mock_ftutils_execute): - CONST.__setattr__('INSTALLER_TYPE', self.installer_type) - CONST.__setattr__('INSTALLER_IP', self.installer_ip) - cmd = ("fetch_os_creds.sh -d %s -i %s -a %s" - % (self.openstack_creds, - self.installer_type, - self.installer_ip)) - self.cli_os.openstack_creds = self.openstack_creds - self.cli_os.fetch_credentials() - mock_click_echo.assert_called_once_with("Fetching credentials from " - "installer node '%s' with " - "IP=%s.." % - (self.installer_type, - self.installer_ip)) - mock_ftutils_execute.assert_called_once_with(cmd, verbose=False) - - @mock.patch('functest.cli.commands.cli_os.ft_utils.execute_command') - @mock.patch('functest.cli.commands.cli_os.os.path.isfile', - return_value=False) - @mock.patch('functest.cli.commands.cli_os.click.echo') - def test_fetch_credentials_missing_installer_type(self, mock_click_echo, - mock_os_path, - mock_ftutils_execute): - CONST.__setattr__('INSTALLER_TYPE', None) - CONST.__setattr__('INSTALLER_IP', self.installer_ip) - cmd = ("fetch_os_creds.sh -d %s -i %s -a %s" - % (self.openstack_creds, - None, - self.installer_ip)) - self.cli_os.openstack_creds = self.openstack_creds - self.cli_os.fetch_credentials() - mock_click_echo.assert_any_call("The environment variable " - "'INSTALLER_TYPE' is not" - "defined. Please export it") - mock_click_echo.assert_any_call("Fetching credentials from " - "installer node '%s' with " - "IP=%s.." % - (None, - self.installer_ip)) - mock_ftutils_execute.assert_called_once_with(cmd, verbose=False) - - @mock.patch('functest.cli.commands.cli_os.ft_utils.execute_command') - @mock.patch('functest.cli.commands.cli_os.os.path.isfile', - return_value=False) - @mock.patch('functest.cli.commands.cli_os.click.echo') - def test_fetch_credentials_missing_installer_ip(self, mock_click_echo, - mock_os_path, - mock_ftutils_execute): - installer_type = self.installer_type - installer_ip = None - CONST.__setattr__('INSTALLER_TYPE', installer_type) - CONST.__setattr__('INSTALLER_IP', installer_ip) - cmd = ("fetch_os_creds.sh -d %s -i %s -a %s" - % (self.openstack_creds, - installer_type, - installer_ip)) - self.cli_os.openstack_creds = self.openstack_creds - self.cli_os.fetch_credentials() - mock_click_echo.assert_any_call("The environment variable " - "'INSTALLER_IP' is not" - "defined. Please export it") - mock_click_echo.assert_any_call("Fetching credentials from " - "installer node '%s' with " - "IP=%s.." % - (installer_type, - installer_ip)) - mock_ftutils_execute.assert_called_once_with(cmd, verbose=False) - - @mock.patch('functest.cli.commands.cli_os.ft_utils.execute_command') def test_check(self, mock_ftutils_execute): with mock.patch.object(self.cli_os, 'ping_endpoint'): - CONST.__setattr__('dir_repo_functest', self.dir_repo_functest) - cmd = os.path.join(CONST.__getattribute__('dir_repo_functest'), - "functest/ci/check_os.sh") self.cli_os.check() - mock_ftutils_execute.assert_called_once_with(cmd, verbose=False) + mock_ftutils_execute.assert_called_once_with( + "sh %s" % pkg_resources.resource_filename( + 'functest', 'ci/check_os.sh'), verbose=False) @mock.patch('functest.cli.commands.cli_os.os.path.isfile', return_value=False) diff --git a/functest/tests/unit/cli/commands/test_cli_testcase.py b/functest/tests/unit/cli/commands/test_cli_testcase.py index fddfc317..4d0bdc2f 100644 --- a/functest/tests/unit/cli/commands/test_cli_testcase.py +++ b/functest/tests/unit/cli/commands/test_cli_testcase.py @@ -7,12 +7,12 @@ import logging +import pkg_resources import unittest import mock from functest.cli.commands import cli_testcase -from functest.utils.constants import CONST class CliTestCasesTesting(unittest.TestCase): @@ -39,9 +39,9 @@ class CliTestCasesTesting(unittest.TestCase): return_value=True) @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') def test_run_default(self, mock_ft_utils, mock_os): - cmd = ("python %s/functest/ci/run_tests.py " - "%s -t %s" % - (CONST.__getattribute__('dir_repo_functest'), + cmd = ("python %s %s -t %s" % + (pkg_resources.resource_filename( + 'functest', 'ci/run_tests.py'), "-n -r ", self.testname)) self.cli_tests.run(self.testname, noclean=True, report=True) mock_ft_utils.assert_called_with(cmd) @@ -50,9 +50,9 @@ class CliTestCasesTesting(unittest.TestCase): return_value=True) @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') def test_run_noclean_missing_report(self, mock_ft_utils, mock_os): - cmd = ("python %s/functest/ci/run_tests.py " - "%s -t %s" % - (CONST.__getattribute__('dir_repo_functest'), + cmd = ("python %s %s -t %s" % + (pkg_resources.resource_filename( + 'functest', 'ci/run_tests.py'), "-n ", self.testname)) self.cli_tests.run(self.testname, noclean=True, report=False) mock_ft_utils.assert_called_with(cmd) @@ -61,9 +61,9 @@ class CliTestCasesTesting(unittest.TestCase): return_value=True) @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') def test_run_report_missing_noclean(self, mock_ft_utils, mock_os): - cmd = ("python %s/functest/ci/run_tests.py " - "%s -t %s" % - (CONST.__getattribute__('dir_repo_functest'), + cmd = ("python %s %s -t %s" % + (pkg_resources.resource_filename( + 'functest', 'ci/run_tests.py'), "-r ", self.testname)) self.cli_tests.run(self.testname, noclean=False, report=True) mock_ft_utils.assert_called_with(cmd) @@ -72,9 +72,9 @@ class CliTestCasesTesting(unittest.TestCase): return_value=True) @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') def test_run_missing_noclean_report(self, mock_ft_utils, mock_os): - cmd = ("python %s/functest/ci/run_tests.py " - "%s -t %s" % - (CONST.__getattribute__('dir_repo_functest'), + cmd = ("python %s %s -t %s" % + (pkg_resources.resource_filename( + 'functest', 'ci/run_tests.py'), "", self.testname)) self.cli_tests.run(self.testname, noclean=False, report=False) mock_ft_utils.assert_called_with(cmd) diff --git a/functest/tests/unit/cli/commands/test_cli_tier.py b/functest/tests/unit/cli/commands/test_cli_tier.py index 550eec93..b42e3581 100644 --- a/functest/tests/unit/cli/commands/test_cli_tier.py +++ b/functest/tests/unit/cli/commands/test_cli_tier.py @@ -7,12 +7,12 @@ import logging +import pkg_resources import unittest import mock from functest.cli.commands import cli_tier -from functest.utils.constants import CONST class CliTierTesting(unittest.TestCase): @@ -87,9 +87,9 @@ class CliTierTesting(unittest.TestCase): return_value=True) @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') def test_run_default(self, mock_ft_utils, mock_os): - cmd = ("python %s/functest/ci/run_tests.py " - "%s -t %s" % - (CONST.__getattribute__('dir_repo_functest'), + cmd = ("python %s %s -t %s" % + (pkg_resources.resource_filename( + 'functest', 'ci/run_tests.py'), "-n -r ", self.tiername)) self.cli_tier.run(self.tiername, noclean=True, report=True) mock_ft_utils.assert_called_with(cmd) @@ -98,9 +98,9 @@ class CliTierTesting(unittest.TestCase): return_value=True) @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') def test_run_report_missing_noclean(self, mock_ft_utils, mock_os): - cmd = ("python %s/functest/ci/run_tests.py " - "%s -t %s" % - (CONST.__getattribute__('dir_repo_functest'), + cmd = ("python %s %s -t %s" % + (pkg_resources.resource_filename( + 'functest', 'ci/run_tests.py'), "-r ", self.tiername)) self.cli_tier.run(self.tiername, noclean=False, report=True) mock_ft_utils.assert_called_with(cmd) @@ -109,9 +109,9 @@ class CliTierTesting(unittest.TestCase): return_value=True) @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') def test_run_noclean_missing_report(self, mock_ft_utils, mock_os): - cmd = ("python %s/functest/ci/run_tests.py " - "%s -t %s" % - (CONST.__getattribute__('dir_repo_functest'), + cmd = ("python %s %s -t %s" % + (pkg_resources.resource_filename( + 'functest', 'ci/run_tests.py'), "-n ", self.tiername)) self.cli_tier.run(self.tiername, noclean=True, report=False) mock_ft_utils.assert_called_with(cmd) @@ -120,9 +120,9 @@ class CliTierTesting(unittest.TestCase): return_value=True) @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') def test_run_missing_noclean_report(self, mock_ft_utils, mock_os): - cmd = ("python %s/functest/ci/run_tests.py " - "%s -t %s" % - (CONST.__getattribute__('dir_repo_functest'), + cmd = ("python %s %s -t %s" % + (pkg_resources.resource_filename( + 'functest', 'ci/run_tests.py'), "", self.tiername)) self.cli_tier.run(self.tiername, noclean=False, report=False) mock_ft_utils.assert_called_with(cmd) diff --git a/functest/tests/unit/cli/test_cli_base.py b/functest/tests/unit/cli/test_cli_base.py index 89603279..61bd093e 100644 --- a/functest/tests/unit/cli/test_cli_base.py +++ b/functest/tests/unit/cli/test_cli_base.py @@ -62,13 +62,6 @@ class CliBaseTesting(unittest.TestCase): self.assertEqual(result.exit_code, 0) self.assertTrue(mock_method.called) - def test_os_fetch_rc(self): - with mock.patch.object(self._openstack, 'fetch_credentials') \ - as mock_method: - result = self.runner.invoke(cli_base.os_fetch_rc) - self.assertEqual(result.exit_code, 0) - self.assertTrue(mock_method.called) - def test_env_prepare(self): with mock.patch.object(self._env, 'prepare') as mock_method: result = self.runner.invoke(cli_base.env_prepare) |