aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit/cli
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-01-23 11:19:41 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2018-01-24 15:15:34 +0100
commitbbfe9b09d2b1ac7bfe286311fef83d36c6125c96 (patch)
treec11ad97f5672454a3b7e2ba13916034919933e5d /functest/tests/unit/cli
parentc653ed78d7721b9933e08015e45dd39379aa4316 (diff)
Fix pylint warnings/errors in cli
cli_testcase and cli_tier have been refactored to avoid duplicating code. Then functest/cli and funtest/unit/cli can be added to the list of modules rated 10/10. Change-Id: Iec90e806397248a10f39080ec554e3f0a6eda7c1 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/tests/unit/cli')
-rw-r--r--functest/tests/unit/cli/commands/test_cli_env.py23
-rw-r--r--functest/tests/unit/cli/commands/test_cli_os.py17
-rw-r--r--functest/tests/unit/cli/commands/test_cli_testcase.py10
-rw-r--r--functest/tests/unit/cli/commands/test_cli_tier.py17
-rw-r--r--functest/tests/unit/cli/test_cli_base.py8
5 files changed, 35 insertions, 40 deletions
diff --git a/functest/tests/unit/cli/commands/test_cli_env.py b/functest/tests/unit/cli/commands/test_cli_env.py
index b5c65377..e5c409bf 100644
--- a/functest/tests/unit/cli/commands/test_cli_env.py
+++ b/functest/tests/unit/cli/commands/test_cli_env.py
@@ -17,15 +17,13 @@ from functest.cli.commands import cli_env
from functest.utils.constants import CONST
-class RegexMatch(object):
+class RegexMatch(object): # pylint: disable=too-few-public-methods
def __init__(self, msg):
self.msg = msg
def __eq__(self, other):
match = re.search(self.msg, other)
- if match:
- return True
- return False
+ return match is not None
class CliEnvTesting(unittest.TestCase):
@@ -34,34 +32,35 @@ class CliEnvTesting(unittest.TestCase):
self.cli_environ = cli_env.CliEnv()
def _test_show_missing_env_var(self, var, *args):
+ # pylint: disable=unused-argument
if var == 'INSTALLER_TYPE':
CONST.__setattr__('INSTALLER_TYPE', None)
- reg_string = "| INSTALLER: Unknown, \S+\s*|"
+ reg_string = r"| INSTALLER: Unknown, \S+\s*|"
elif var == 'INSTALLER_IP':
CONST.__setattr__('INSTALLER_IP', None)
- reg_string = "| INSTALLER: \S+, Unknown\s*|"
+ reg_string = r"| INSTALLER: \S+, Unknown\s*|"
elif var == 'SCENARIO':
CONST.__setattr__('DEPLOY_SCENARIO', None)
- reg_string = "| SCENARIO: Unknown\s*|"
+ reg_string = r"| SCENARIO: Unknown\s*|"
elif var == 'NODE':
CONST.__setattr__('NODE_NAME', None)
- reg_string = "| POD: Unknown\s*|"
+ reg_string = r"| POD: Unknown\s*|"
elif var == 'BUILD_TAG':
CONST.__setattr__('BUILD_TAG', None)
- reg_string = "| BUILD TAG: None|"
+ reg_string = r"| BUILD TAG: None|"
elif var == 'DEBUG':
CONST.__setattr__('CI_DEBUG', None)
- reg_string = "| DEBUG FLAG: false\s*|"
+ reg_string = r"| 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(RegexMatch(reg_string))
- def test_show_missing_ci_installer_type(self, *args):
+ def test_show_ci_installer_type_ko(self, *args):
self._test_show_missing_env_var('INSTALLER_TYPE', *args)
- def test_show_missing_ci_installer_ip(self, *args):
+ def test_show_ci_installer_ip_ko(self, *args):
self._test_show_missing_env_var('INSTALLER_IP', *args)
def test_show_missing_ci_scenario(self, *args):
diff --git a/functest/tests/unit/cli/commands/test_cli_os.py b/functest/tests/unit/cli/commands/test_cli_os.py
index e4854cd6..26956e08 100644
--- a/functest/tests/unit/cli/commands/test_cli_os.py
+++ b/functest/tests/unit/cli/commands/test_cli_os.py
@@ -37,27 +37,24 @@ class CliOpenStackTesting(unittest.TestCase):
@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):
+ def test_ping_endpoint_auth_url_ko(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_click_echo.assert_called_once_with(
+ "Source the OpenStack credentials first '. $creds'")
+ mock_exit.assert_called_once_with(0)
@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):
+ def test_ping_endpoint_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_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):
diff --git a/functest/tests/unit/cli/commands/test_cli_testcase.py b/functest/tests/unit/cli/commands/test_cli_testcase.py
index 9ed7d829..30e55fac 100644
--- a/functest/tests/unit/cli/commands/test_cli_testcase.py
+++ b/functest/tests/unit/cli/commands/test_cli_testcase.py
@@ -19,28 +19,28 @@ class CliTestCasesTesting(unittest.TestCase):
def setUp(self):
self.testname = 'testname'
- with mock.patch('functest.cli.commands.cli_testcase.tb'):
+ with mock.patch('functest.ci.tier_builder'):
self.cli_tests = cli_testcase.CliTestcase()
- @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
+ @mock.patch('functest.utils.functest_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')
+ @mock.patch('functest.utils.functest_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')
+ @mock.patch('functest.utils.functest_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')
+ @mock.patch('functest.utils.functest_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)
diff --git a/functest/tests/unit/cli/commands/test_cli_tier.py b/functest/tests/unit/cli/commands/test_cli_tier.py
index 49c3c7a3..f81ad31d 100644
--- a/functest/tests/unit/cli/commands/test_cli_tier.py
+++ b/functest/tests/unit/cli/commands/test_cli_tier.py
@@ -20,7 +20,7 @@ class CliTierTesting(unittest.TestCase):
def setUp(self):
self.tiername = 'tiername'
self.testnames = 'testnames'
- with mock.patch('functest.cli.commands.cli_tier.tb'):
+ with mock.patch('functest.ci.tier_builder'):
self.cli_tier = cli_tier.CliTier()
@mock.patch('functest.cli.commands.cli_tier.click.echo')
@@ -58,10 +58,9 @@ class CliTierTesting(unittest.TestCase):
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_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):
@@ -75,25 +74,25 @@ class CliTierTesting(unittest.TestCase):
":\n %s\n" % (self.tiername,
'tiernames'))
- @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command')
+ @mock.patch('functest.utils.functest_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')
+ @mock.patch('functest.utils.functest_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')
+ @mock.patch('functest.utils.functest_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')
+ @mock.patch('functest.utils.functest_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)
diff --git a/functest/tests/unit/cli/test_cli_base.py b/functest/tests/unit/cli/test_cli_base.py
index 5ac1fda9..876e8aa1 100644
--- a/functest/tests/unit/cli/test_cli_base.py
+++ b/functest/tests/unit/cli/test_cli_base.py
@@ -26,10 +26,10 @@ class CliBaseTesting(unittest.TestCase):
def setUp(self):
self.runner = CliRunner()
- self._openstack = cli_base._openstack
- self._env = cli_base._env
- self._testcase = cli_base._testcase
- self._tier = cli_base._tier
+ self._openstack = cli_base.OPENSTACK
+ self._env = cli_base.ENV
+ self._testcase = cli_base.TESTCASE
+ self._tier = cli_base.TIER
def test_os_check(self):
with mock.patch.object(self._openstack, 'check') as mock_method: