summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-01-21 01:02:20 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2018-01-21 14:53:47 +0100
commit2030e14451a072844e750318de0d5efc47d4500c (patch)
tree47e79f3244d233d6edbe11e30150185ed12a59e0
parenta6df43da7ab4de653eecbc9b6380d5fc7ce7bc14 (diff)
Fully test and cover functest/ci/tier_*
It also fixes check_deployment.py and ci unit tests which were wrong when testing exceptions. Now ci modules are rated 10/10 and fully covered. Change-Id: I30dca491b44cc54aa1abc0d0433c00b4dcabfdc4 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/ci/check_deployment.py29
-rw-r--r--functest/ci/tier_builder.py23
-rw-r--r--functest/tests/unit/ci/test_check_deployment.py359
-rw-r--r--functest/tests/unit/ci/test_run_tests.py12
-rw-r--r--functest/tests/unit/ci/test_tier_builder.py41
-rw-r--r--functest/tests/unit/ci/test_tier_handler.py119
-rw-r--r--tox.ini7
7 files changed, 338 insertions, 252 deletions
diff --git a/functest/ci/check_deployment.py b/functest/ci/check_deployment.py
index 9453c6d49..81607dffe 100644
--- a/functest/ci/check_deployment.py
+++ b/functest/ci/check_deployment.py
@@ -18,18 +18,18 @@ Verifies that:
import logging
import logging.config
import os
-import pkg_resources
-from six.moves import urllib
import socket
-from functest.opnfv_tests.openstack.snaps import snaps_utils
-
+import pkg_resources
+from six.moves import urllib
from snaps.openstack.tests import openstack_tests
from snaps.openstack.utils import glance_utils
from snaps.openstack.utils import keystone_utils
from snaps.openstack.utils import neutron_utils
from snaps.openstack.utils import nova_utils
+from functest.opnfv_tests.openstack.snaps import snaps_utils
+
__author__ = "Jose Lausuch <jose.lausuch@ericsson.com>"
LOGGER = logging.getLogger(__name__)
@@ -37,18 +37,21 @@ LOGGER = logging.getLogger(__name__)
def verify_connectivity(endpoint):
""" Returns true if an hostname/port is reachable"""
- connection = socket.socket()
- connection.settimeout(10)
- hostname = urllib.parse.urlparse(endpoint).hostname
- port = urllib.parse.urlparse(endpoint).port
- if not port:
- port = 443 if urllib.parse.urlparse(endpoint).scheme == "https" else 80
try:
- connection.connect((hostname, port))
- LOGGER.debug('%s:%s is reachable!', hostname, port)
+ connection = socket.socket()
+ connection.settimeout(10)
+ url = urllib.parse.urlparse(endpoint)
+ port = url.port
+ if not port:
+ port = 443 if url.scheme == "https" else 80
+ connection.connect(url.hostname, port)
+ LOGGER.debug('%s:%s is reachable!', url.hostname, port)
return True
except socket.error:
- LOGGER.exception('%s:%s is not reachable.', hostname, port)
+ LOGGER.error('%s:%s is not reachable.', url.hostname, port)
+ except Exception: # pylint: disable=broad-except
+ LOGGER.exception(
+ 'Errors when verifying connectivity to %s:%s', url.hostname, port)
return False
diff --git a/functest/ci/tier_builder.py b/functest/ci/tier_builder.py
index 9e92599d8..370ab94d9 100644
--- a/functest/ci/tier_builder.py
+++ b/functest/ci/tier_builder.py
@@ -40,24 +40,23 @@ class TierBuilder(object):
del self.tier_objects[:]
for dic_tier in self.dic_tier_array:
- tier = th.Tier(name=dic_tier['name'],
- order=dic_tier['order'],
- ci_loop=dic_tier['ci_loop'],
- description=dic_tier['description'])
+ tier = th.Tier(
+ name=dic_tier['name'], order=dic_tier['order'],
+ ci_loop=dic_tier['ci_loop'],
+ description=dic_tier['description'])
for dic_testcase in dic_tier['testcases']:
installer = dic_testcase['dependencies']['installer']
scenario = dic_testcase['dependencies']['scenario']
dep = th.Dependency(installer, scenario)
- testcase = th.TestCase(name=dic_testcase['case_name'],
- enabled=dic_testcase.get(
- 'enabled', True),
- dependency=dep,
- criteria=dic_testcase['criteria'],
- blocking=dic_testcase['blocking'],
- description=dic_testcase['description'],
- project=dic_testcase['project_name'])
+ testcase = th.TestCase(
+ name=dic_testcase['case_name'],
+ enabled=dic_testcase.get('enabled', True),
+ dependency=dep, criteria=dic_testcase['criteria'],
+ blocking=dic_testcase['blocking'],
+ description=dic_testcase['description'],
+ project=dic_testcase['project_name'])
if (testcase.is_compatible(self.ci_installer,
self.ci_scenario) and
testcase.is_enabled()):
diff --git a/functest/tests/unit/ci/test_check_deployment.py b/functest/tests/unit/ci/test_check_deployment.py
index fc6368e5a..46dcc24c5 100644
--- a/functest/tests/unit/ci/test_check_deployment.py
+++ b/functest/tests/unit/ci/test_check_deployment.py
@@ -7,9 +7,13 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
+import socket
+import unittest
+
import logging
import mock
-import unittest
from functest.ci import check_deployment
@@ -18,7 +22,7 @@ __author__ = "Jose Lausuch <jose.lausuch@ericsson.com>"
class CheckDeploymentTesting(unittest.TestCase):
"""The super class which testing classes could inherit."""
- # pylint: disable=missing-docstring
+ # pylint: disable=missing-docstring,too-many-public-methods
logging.disable(logging.CRITICAL)
@@ -38,160 +42,243 @@ class CheckDeploymentTesting(unittest.TestCase):
self.os_creds.proxy_settings = proxy_settings
self.deployment.os_creds = self.os_creds
- def test_check_rc(self):
- with mock.patch('functest.ci.check_deployment.os.path.isfile',
- returns=True) as m, \
- mock.patch('six.moves.builtins.open',
- mock.mock_open(read_data='OS_AUTH_URL')):
+ @mock.patch('socket.socket.connect', side_effect=TypeError)
+ def test_verify_connectivity_ko1(self, *args):
+ self.assertFalse(check_deployment.verify_connectivity("127.0.0.1"))
+ args[0].assert_called_once_with(None, 80)
+
+ @mock.patch('socket.socket.connect', side_effect=socket.error)
+ def test_verify_connectivity_ko2(self, *args):
+ self.assertFalse(
+ check_deployment.verify_connectivity("http://127.0.0.1"))
+ args[0].assert_called_once_with("127.0.0.1", 80)
+
+ @mock.patch('socket.socket.connect', side_effect=socket.error)
+ def test_verify_connectivity_ko3(self, *args):
+ self.assertFalse(
+ check_deployment.verify_connectivity("https://127.0.0.1"))
+ args[0].assert_called_once_with("127.0.0.1", 443)
+
+ @mock.patch('socket.socket.connect')
+ def test_verify_connectivity(self, *args):
+ self.assertTrue(
+ check_deployment.verify_connectivity("https://127.0.0.1"))
+ args[0].assert_called_once_with("127.0.0.1", 443)
+
+ @mock.patch('snaps.openstack.utils.keystone_utils.keystone_session',
+ return_value=mock.Mock(
+ get_token=mock.Mock(side_effect=Exception)))
+ def test_get_auth_token_ko(self, *args):
+ with self.assertRaises(Exception):
+ check_deployment.get_auth_token(self.os_creds)
+ args[0].assert_called_once_with(self.os_creds)
+
+ @mock.patch('snaps.openstack.utils.keystone_utils.keystone_session',
+ return_value=mock.Mock(
+ get_token=mock.Mock(return_value="foo")))
+ def test_get_auth_token(self, *args):
+ self.assertEqual(check_deployment.get_auth_token(self.os_creds), "foo")
+ args[0].assert_called_once_with(self.os_creds)
+
+ @mock.patch('six.moves.builtins.open',
+ mock.mock_open(read_data='OS_AUTH_URL'))
+ @mock.patch('functest.ci.check_deployment.os.path.isfile', returns=True)
+ def test_check_rc(self, *args):
+ self.deployment.check_rc()
+ args[0].assert_called_once_with(self.rc_file)
+
+ @mock.patch('functest.ci.check_deployment.os.path.isfile',
+ return_value=False)
+ def test_check_rc_missing_file(self, *args):
+ with self.assertRaises(Exception) as context:
self.deployment.check_rc()
- self.assertTrue(m.called)
-
- def test_check_rc_missing_file(self):
- with mock.patch('functest.ci.check_deployment.os.path.isfile',
- return_value=False), \
- self.assertRaises(Exception) as context:
- msg = 'RC file {} does not exist!'.format(self.rc_file)
- self.deployment.check_rc(self.rc_file)
- self.assertTrue(msg in context)
-
- def test_check_rc_missing_os_auth(self):
- with mock.patch('six.moves.builtins.open',
- mock.mock_open(read_data='test')), \
- self.assertRaises(Exception) as context:
- msg = 'OS_AUTH_URL not defined in {}.'.format(self.rc_file)
- self.assertTrue(msg in context)
-
- def test_check_auth_endpoint(self):
- with mock.patch('functest.ci.check_deployment.verify_connectivity',
- return_value=True) as m,\
- mock.patch('functest.ci.check_deployment.get_auth_token',
- return_value='gAAAAABaOhXGS') as mock_token:
- self.deployment.check_auth_endpoint()
- self.assertTrue(m.called)
- self.assertTrue(mock_token.called)
-
- def test_check_auth_endpoint_not_reachable(self):
- with mock.patch('functest.ci.check_deployment.verify_connectivity',
- return_value=False) as m, \
- self.assertRaises(Exception) as context:
- endpoint = self.os_creds.auth_url
+ args[0].assert_called_once_with(self.rc_file)
+ msg = 'RC file {} does not exist!'.format(self.rc_file)
+ self.assertTrue(msg in str(context.exception))
+
+ @mock.patch('six.moves.builtins.open',
+ mock.mock_open(read_data='test'))
+ @mock.patch('functest.ci.check_deployment.os.path.isfile',
+ return_value=True)
+ def test_check_rc_missing_os_auth(self, *args):
+ with self.assertRaises(Exception) as context:
+ self.deployment.check_rc()
+ args[0].assert_called_once_with(self.rc_file)
+ msg = 'OS_AUTH_URL not defined in {}.'.format(self.rc_file)
+ self.assertTrue(msg in str(context.exception))
+
+ @mock.patch('functest.ci.check_deployment.get_auth_token',
+ return_value='gAAAAABaOhXGS')
+ @mock.patch('functest.ci.check_deployment.verify_connectivity',
+ return_value=True)
+ def test_check_auth_endpoint(self, *args):
+ self.deployment.check_auth_endpoint()
+ args[0].assert_called_once_with(self.endpoint_test)
+ args[1].assert_called_once_with(mock.ANY)
+
+ @mock.patch('functest.ci.check_deployment.verify_connectivity',
+ return_value=False)
+ def test_check_auth_endpoint_ko(self, *args):
+ with self.assertRaises(Exception) as context:
self.deployment.check_auth_endpoint()
- msg = "OS_AUTH_URL {} is not reachable.".format(endpoint)
- self.assertTrue(m.called)
- self.assertTrue(msg in context)
-
- def test_check_public_endpoint(self):
- with mock.patch('functest.ci.check_deployment.verify_connectivity',
- return_value=True) as m, \
- mock.patch('functest.ci.check_deployment.keystone_utils.'
- 'get_endpoint') as n:
- self.deployment.check_public_endpoint()
- self.assertTrue(m.called)
- self.assertTrue(n.called)
-
- def test_check_public_endpoint_not_reachable(self):
- with mock.patch('functest.ci.check_deployment.verify_connectivity',
- return_value=False) as m, \
- mock.patch('functest.ci.check_deployment.keystone_utils.'
- 'get_endpoint',
- return_value=self.endpoint_test) as n, \
- self.assertRaises(Exception) as context:
+ msg = "OS_AUTH_URL {} is not reachable.".format(self.os_creds.auth_url)
+ args[0].assert_called_once_with(self.os_creds.auth_url)
+ self.assertTrue(msg in str(context.exception))
+
+ @mock.patch('functest.ci.check_deployment.verify_connectivity',
+ return_value=True)
+ @mock.patch('functest.ci.check_deployment.keystone_utils.get_endpoint')
+ def test_check_public_endpoint(self, *args):
+ args[0].return_value = self.endpoint_test
+ self.deployment.check_public_endpoint()
+ args[0].assert_called_once_with(
+ mock.ANY, 'identity', interface='public')
+ args[1].assert_called_once_with(self.endpoint_test)
+
+ @mock.patch('functest.ci.check_deployment.verify_connectivity',
+ return_value=False)
+ @mock.patch('functest.ci.check_deployment.keystone_utils.get_endpoint')
+ def test_check_public_endpoint_ko(self, *args):
+ args[0].return_value = self.endpoint_test
+ with self.assertRaises(Exception) as context:
self.deployment.check_public_endpoint()
- msg = ("Public endpoint {} is not reachable."
- .format(self.mock_endpoint))
- self.assertTrue(m.called)
- self.assertTrue(n.called)
- self.assertTrue(msg in context)
-
- def test_check_service_endpoint(self):
- with mock.patch('functest.ci.check_deployment.verify_connectivity',
- return_value=True) as m, \
- mock.patch('functest.ci.check_deployment.keystone_utils.'
- 'get_endpoint') as n:
- self.deployment.check_service_endpoint(self.service_test)
- self.assertTrue(m.called)
- self.assertTrue(n.called)
-
- def test_check_service_endpoint_not_reachable(self):
- with mock.patch('functest.ci.check_deployment.verify_connectivity',
- return_value=False) as m, \
- mock.patch('functest.ci.check_deployment.keystone_utils.'
- 'get_endpoint',
- return_value=self.endpoint_test) as n, \
- self.assertRaises(Exception) as context:
+ args[0].assert_called_once_with(
+ mock.ANY, 'identity', interface='public')
+ args[1].assert_called_once_with(self.endpoint_test)
+ msg = "Public endpoint {} is not reachable.".format(self.endpoint_test)
+ self.assertTrue(msg in str(context.exception))
+
+ @mock.patch('functest.ci.check_deployment.verify_connectivity',
+ return_value=True)
+ @mock.patch('functest.ci.check_deployment.keystone_utils.get_endpoint')
+ def test_check_service_endpoint(self, *args):
+ self.deployment.check_service_endpoint(self.service_test)
+ args[0].assert_called_once_with(
+ mock.ANY, self.service_test, interface='public')
+ args[1].assert_called_once_with(args[0].return_value)
+
+ @mock.patch('functest.ci.check_deployment.verify_connectivity',
+ return_value=False)
+ @mock.patch('functest.ci.check_deployment.keystone_utils.get_endpoint')
+ def test_check_service_endpoint_ko(self, *args):
+ args[0].return_value = self.endpoint_test
+ with self.assertRaises(Exception) as context:
self.deployment.check_service_endpoint(self.service_test)
- msg = "{} endpoint {} is not reachable.".format(self.service_test,
- self.endpoint_test)
- self.assertTrue(m.called)
- self.assertTrue(n.called)
- self.assertTrue(msg in context)
-
- def test_check_nova(self):
- with mock.patch('functest.ci.check_deployment.nova_utils.nova_client',
- return_value=self.client_test) as m:
- self.deployment.check_nova()
- self.assertTrue(m.called)
+ msg = "{} endpoint {} is not reachable.".format(
+ self.service_test, self.endpoint_test)
+ self.assertTrue(msg in str(context.exception))
+ args[0].assert_called_once_with(
+ mock.ANY, self.service_test, interface='public')
+ args[1].assert_called_once_with(args[0].return_value)
+
+ @mock.patch('functest.ci.check_deployment.nova_utils.nova_client')
+ def test_check_nova(self, mock_method):
+ self.deployment.check_nova()
+ mock_method.assert_called_once_with(mock.ANY)
- def test_check_nova_fail(self):
- with mock.patch('functest.ci.check_deployment.nova_utils.nova_client',
- return_value=self.client_test) as m, \
- mock.patch.object(self.client_test, 'servers.list',
- side_effect=Exception):
+ @mock.patch('functest.ci.check_deployment.nova_utils.nova_client',
+ return_value=mock.Mock(
+ servers=mock.Mock(list=mock.Mock(side_effect=Exception))))
+ def test_check_nova_fail(self, mock_method):
+ with self.assertRaises(Exception):
self.deployment.check_nova()
- self.assertTrue(m.called)
- self.assertRaises(Exception)
+ mock_method.assert_called_once_with(mock.ANY)
- def test_check_neutron(self):
- with mock.patch('functest.ci.check_deployment.neutron_utils.'
- 'neutron_client', return_value=self.client_test) as m:
- self.deployment.check_neutron()
- self.assertTrue(m.called)
-
- def test_check_neutron_fail(self):
- with mock.patch('functest.ci.check_deployment.neutron_utils.'
- 'neutron_client',
- return_value=self.client_test) as m, \
- mock.patch.object(self.client_test, 'list_networks',
- side_effect=Exception), \
- self.assertRaises(Exception):
+ @mock.patch('functest.ci.check_deployment.neutron_utils.neutron_client')
+ def test_check_neutron(self, mock_method):
+ self.deployment.check_neutron()
+ mock_method.assert_called_once_with(mock.ANY)
+
+ @mock.patch('functest.ci.check_deployment.neutron_utils.neutron_client',
+ return_value=mock.Mock(
+ list_networks=mock.Mock(side_effect=Exception)))
+ def test_check_neutron_fail(self, mock_method):
+ with self.assertRaises(Exception):
self.deployment.check_neutron()
- self.assertRaises(Exception)
- self.assertTrue(m.called)
+ mock_method.assert_called_once_with(mock.ANY)
- def test_check_glance(self):
- with mock.patch('functest.ci.check_deployment.glance_utils.'
- 'glance_client', return_value=self.client_test) as m:
- self.deployment.check_glance()
- self.assertTrue(m.called)
+ @mock.patch('functest.ci.check_deployment.glance_utils.glance_client')
+ def test_check_glance(self, mock_method):
+ self.deployment.check_glance()
+ mock_method.assert_called_once_with(mock.ANY)
- def test_check_glance_fail(self):
- with mock.patch('functest.ci.check_deployment.glance_utils.'
- 'glance_client', return_value=self.client_test) as m, \
- mock.patch.object(self.client_test, 'images.list',
- side_effect=Exception):
+ @mock.patch('functest.ci.check_deployment.glance_utils.glance_client',
+ return_value=mock.Mock(
+ images=mock.Mock(list=mock.Mock(side_effect=Exception))))
+ def test_check_glance_fail(self, mock_method):
+ with self.assertRaises(Exception):
self.deployment.check_glance()
- self.assertRaises(Exception)
- self.assertTrue(m.called)
+ mock_method.assert_called_once_with(mock.ANY)
@mock.patch('functest.ci.check_deployment.LOGGER.info')
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
- 'get_ext_net_name')
- def test_check_extnet(self, mock_getext, mock_loginfo):
- test_network = 'ext-net'
- mock_getext.return_value = test_network
+ 'get_ext_net_name', return_value='ext-net')
+ def test_check_extnet(self, *args):
self.deployment.check_ext_net()
- self.assertTrue(mock_getext.called)
- mock_loginfo.assert_called_once_with(
- "External network found: %s", test_network)
+ args[0].assert_called_once_with(mock.ANY)
+ args[1].assert_called_once_with(
+ "External network found: %s", "ext-net")
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
'get_ext_net_name', return_value='')
- def test_check_extnet_None(self, mock_getext):
+ def test_check_extnet_none(self, mock_getext):
with self.assertRaises(Exception) as context:
self.deployment.check_ext_net()
- self.assertTrue(mock_getext.called)
- msg = 'ERROR: No external networks in the deployment.'
- self.assertTrue(msg in context)
+ self.assertTrue(mock_getext.called)
+ msg = 'ERROR: No external networks in the deployment.'
+ self.assertTrue(msg in str(context.exception))
+
+ @mock.patch('functest.ci.check_deployment.CheckDeployment.check_rc',
+ side_effect=Exception)
+ def test_check_all_exc1(self, *args):
+ with self.assertRaises(Exception):
+ self.deployment.check_all()
+ args[0].assert_called_once_with()
+
+ @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials',
+ side_effect=Exception)
+ @mock.patch('functest.ci.check_deployment.CheckDeployment.check_rc')
+ def test_check_all_exc2(self, *args):
+ with self.assertRaises(Exception):
+ self.deployment.check_all()
+ args[0].assert_called_once_with()
+ args[1].assert_called_once_with(
+ os_env_file=self.rc_file, proxy_settings_str=None,
+ ssh_proxy_cmd=None)
+
+ @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials',
+ return_value=None)
+ @mock.patch('functest.ci.check_deployment.CheckDeployment.check_rc')
+ def test_check_all_exc3(self, *args):
+ with self.assertRaises(Exception):
+ self.deployment.check_all()
+ args[0].assert_called_once_with()
+ args[1].assert_called_once_with(
+ os_env_file=self.rc_file, proxy_settings_str=None,
+ ssh_proxy_cmd=None)
+
+ @mock.patch('functest.ci.check_deployment.CheckDeployment.check_ext_net')
+ @mock.patch('functest.ci.check_deployment.CheckDeployment.check_glance')
+ @mock.patch('functest.ci.check_deployment.CheckDeployment.check_neutron')
+ @mock.patch('functest.ci.check_deployment.CheckDeployment.check_nova')
+ @mock.patch(
+ 'functest.ci.check_deployment.CheckDeployment.check_service_endpoint')
+ @mock.patch(
+ 'functest.ci.check_deployment.CheckDeployment.check_public_endpoint')
+ @mock.patch(
+ 'functest.ci.check_deployment.CheckDeployment.check_auth_endpoint')
+ @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials')
+ @mock.patch('functest.ci.check_deployment.CheckDeployment.check_rc')
+ def test_check_all(self, *args):
+ self.assertEqual(self.deployment.check_all(), 0)
+ for i in [0, 2, 3, 5, 6, 7, 8]:
+ args[i].assert_called_once_with()
+ args[1].assert_called_once_with(
+ os_env_file=self.rc_file, proxy_settings_str=None,
+ ssh_proxy_cmd=None)
+ calls = [mock.call('compute'), mock.call('network'),
+ mock.call('image')]
+ args[4].assert_has_calls(calls)
if __name__ == "__main__":
diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py
index 93cbfccdf..0db5f2832 100644
--- a/functest/tests/unit/ci/test_run_tests.py
+++ b/functest/tests/unit/ci/test_run_tests.py
@@ -20,12 +20,6 @@ class FakeModule(TestCase):
def run(self):
return TestCase.EX_OK
- def push_to_db(self):
- return TestCase.EX_OK
-
- def is_successful(self):
- return TestCase.EX_OK
-
class RunTestsTesting(unittest.TestCase):
@@ -121,9 +115,9 @@ class RunTestsTesting(unittest.TestCase):
mock.patch('functest.ci.run_tests.Runner.get_run_dict',
return_value=None), \
self.assertRaises(Exception) as context:
- self.runner(mock_test, 'tier_name')
- msg = "Cannot import the class for the test case."
- self.assertTrue(msg in context)
+ self.runner.run_test(mock_test)
+ msg = "Cannot import the class for the test case."
+ self.assertTrue(msg in str(context.exception))
@mock.patch('functest.ci.run_tests.Runner.source_rc_file')
@mock.patch('importlib.import_module', name="module",
diff --git a/functest/tests/unit/ci/test_tier_builder.py b/functest/tests/unit/ci/test_tier_builder.py
index d832ca3f0..ef6a007bb 100644
--- a/functest/tests/unit/ci/test_tier_builder.py
+++ b/functest/tests/unit/ci/test_tier_builder.py
@@ -18,23 +18,17 @@ from functest.ci import tier_builder
class TierBuilderTesting(unittest.TestCase):
def setUp(self):
- self.dependency = {'installer': 'test_installer',
- 'scenario': 'test_scenario'}
-
- self.testcase = {'dependencies': self.dependency,
- 'enabled': 'true',
- 'case_name': 'test_name',
- 'criteria': 'test_criteria',
- 'blocking': 'test_blocking',
- 'description': 'test_desc',
- 'project_name': 'project_name'}
-
- self.dic_tier = {'name': 'test_tier',
- 'order': 'test_order',
- 'ci_loop': 'test_ci_loop',
- 'description': 'test_desc',
- 'testcases': [self.testcase]}
-
+ self.dependency = {
+ 'installer': 'test_installer', 'scenario': 'test_scenario'}
+ self.testcase = {
+ 'dependencies': self.dependency, 'enabled': 'true',
+ 'case_name': 'test_name', 'criteria': 'test_criteria',
+ 'blocking': 'test_blocking', 'description': 'test_desc',
+ 'project_name': 'project_name'}
+ self.dic_tier = {
+ 'name': 'test_tier', 'order': 'test_order',
+ 'ci_loop': 'test_ci_loop', 'description': 'test_desc',
+ 'testcases': [self.testcase]}
self.mock_yaml = mock.Mock()
attrs = {'get.return_value': [self.dic_tier]}
self.mock_yaml.configure_mock(**attrs)
@@ -42,9 +36,8 @@ class TierBuilderTesting(unittest.TestCase):
with mock.patch('functest.ci.tier_builder.yaml.safe_load',
return_value=self.mock_yaml), \
mock.patch('six.moves.builtins.open', mock.mock_open()):
- self.tierbuilder = tier_builder.TierBuilder('test_installer',
- 'test_scenario',
- 'testcases_file')
+ self.tierbuilder = tier_builder.TierBuilder(
+ 'test_installer', 'test_scenario', 'testcases_file')
self.tier_obj = self.tierbuilder.tier_objects[0]
def test_get_tiers(self):
@@ -86,6 +79,14 @@ class TierBuilderTesting(unittest.TestCase):
def test_get_tier_name_ko(self):
self.assertEqual(self.tierbuilder.get_tier_name('test_name2'), None)
+ def test_str(self):
+ message = str(self.tierbuilder)
+ self.assertTrue('test_tier' in message)
+ self.assertTrue('test_order' in message)
+ self.assertTrue('test_ci_loop' in message)
+ self.assertTrue('test_desc' in message)
+ self.assertTrue('test_name' in message)
+
if __name__ == "__main__":
logging.disable(logging.CRITICAL)
diff --git a/functest/tests/unit/ci/test_tier_handler.py b/functest/tests/unit/ci/test_tier_handler.py
index 871220db3..5e7841280 100644
--- a/functest/tests/unit/ci/test_tier_handler.py
+++ b/functest/tests/unit/ci/test_tier_handler.py
@@ -16,31 +16,23 @@ from functest.ci import tier_handler
class TierHandlerTesting(unittest.TestCase):
+ # pylint: disable=too-many-public-methods
def setUp(self):
self.test = mock.Mock()
attrs = {'get_name.return_value': 'test_name'}
self.test.configure_mock(**attrs)
-
self.mock_depend = mock.Mock()
attrs = {'get_scenario.return_value': 'test_scenario',
'get_installer.return_value': 'test_installer'}
self.mock_depend.configure_mock(**attrs)
-
- self.tier = tier_handler.Tier('test_tier',
- 'test_order',
- 'test_ci_loop',
- description='test_desc')
- self.testcase = tier_handler.TestCase('test_name',
- 'true',
- self.mock_depend,
- 'test_criteria',
- 'test_blocking',
- description='test_desc')
-
- self.dependency = tier_handler.Dependency('test_installer',
- 'test_scenario')
-
+ self.tier = tier_handler.Tier(
+ 'test_tier', 'test_order', 'test_ci_loop', description='test_desc')
+ self.testcase = tier_handler.TestCase(
+ 'test_name', 'true', self.mock_depend, 'test_criteria',
+ True, description='test_desc', project='project_name')
+ self.dependency = tier_handler.Dependency(
+ 'test_installer', 'test_scenario')
self.testcase.str = self.testcase.__str__()
self.dependency.str = self.dependency.__str__()
self.tier.str = self.tier.__str__()
@@ -52,89 +44,94 @@ class TierHandlerTesting(unittest.TestCase):
def test_add_test(self):
self.tier.add_test(self.test)
- self.assertEqual(self.tier.tests_array,
- [self.test])
+ self.assertEqual(self.tier.tests_array, [self.test])
+
+ def test_get_skipped_test1(self):
+ self.assertEqual(self.tier.get_skipped_test(), [])
+
+ def test_get_skipped_test2(self):
+ self.tier.skip_test(self.test)
+ self.assertEqual(self.tier.get_skipped_test(), [self.test])
def test_get_tests(self):
self.tier.tests_array = [self.test]
- self.assertEqual(self.tier.get_tests(),
- [self.test])
+ self.assertEqual(self.tier.get_tests(), [self.test])
def test_get_test_names(self):
self.tier.tests_array = [self.test]
- self.assertEqual(self.tier.get_test_names(),
- ['test_name'])
+ self.assertEqual(self.tier.get_test_names(), ['test_name'])
def test_get_test(self):
self.tier.tests_array = [self.test]
- with mock.patch.object(self.tier, 'is_test',
- return_value=True):
- self.assertEqual(self.tier.get_test('test_name'),
- self.test)
+ with mock.patch.object(self.tier, 'is_test', return_value=True):
+ self.assertEqual(self.tier.get_test('test_name'), self.test)
def test_get_test_missing_test(self):
self.tier.tests_array = [self.test]
- with mock.patch.object(self.tier, 'is_test',
- return_value=False):
- self.assertEqual(self.tier.get_test('test_name'),
- None)
+ with mock.patch.object(self.tier, 'is_test', return_value=False):
+ self.assertEqual(self.tier.get_test('test_name'), None)
def test_get_name(self):
- self.assertEqual(self.tier.get_name(),
- 'test_tier')
+ self.assertEqual(self.tier.get_name(), 'test_tier')
def test_get_order(self):
- self.assertEqual(self.tier.get_order(),
- 'test_order')
+ self.assertEqual(self.tier.get_order(), 'test_order')
def test_get_ci_loop(self):
- self.assertEqual(self.tier.get_ci_loop(),
- 'test_ci_loop')
+ self.assertEqual(self.tier.get_ci_loop(), 'test_ci_loop')
def test_testcase_is_none_in_item(self):
- self.assertEqual(tier_handler.TestCase.is_none("item"),
- False)
+ self.assertEqual(tier_handler.TestCase.is_none("item"), False)
def test_testcase_is_none_no_item(self):
- self.assertEqual(tier_handler.TestCase.is_none(None),
- True)
+ self.assertEqual(tier_handler.TestCase.is_none(None), True)
def test_testcase_is_compatible(self):
- self.assertEqual(self.testcase.is_compatible('test_installer',
- 'test_scenario'),
- True)
+ self.assertEqual(
+ self.testcase.is_compatible('test_installer', 'test_scenario'),
+ True)
def test_testcase_is_compatible_2(self):
- self.assertEqual(self.testcase.is_compatible('missing_installer',
- 'test_scenario'),
- False)
- self.assertEqual(self.testcase.is_compatible('test_installer',
- 'missing_scenario'),
- False)
+ self.assertEqual(
+ self.testcase.is_compatible('missing_installer', 'test_scenario'),
+ False)
+ self.assertEqual(
+ self.testcase.is_compatible('test_installer', 'missing_scenario'),
+ False)
+
+ @mock.patch('re.search', side_effect=TypeError)
+ def test_testcase_is_compatible3(self, *args):
+ self.assertEqual(
+ self.testcase.is_compatible('test_installer', 'test_scenario'),
+ False)
+ args[0].assert_called_once_with('test_installer', 'test_installer')
def test_testcase_get_name(self):
- self.assertEqual(self.tier.get_name(),
- 'test_tier')
+ self.assertEqual(self.tier.get_name(), 'test_tier')
def test_testcase_is_enabled(self):
- self.assertEqual(self.testcase.is_enabled(),
- 'true')
+ self.assertEqual(self.testcase.is_enabled(), 'true')
def test_testcase_get_criteria(self):
- self.assertEqual(self.tier.get_order(),
- 'test_order')
+ self.assertEqual(self.testcase.get_criteria(), 'test_criteria')
def test_testcase_is_blocking(self):
- self.assertEqual(self.tier.get_ci_loop(),
- 'test_ci_loop')
+ self.assertTrue(self.testcase.is_blocking())
+
+ def test_testcase_get_project(self):
+ self.assertEqual(self.testcase.get_project(), 'project_name')
+
+ def test_testcase_get_order(self):
+ self.assertEqual(self.tier.get_order(), 'test_order')
+
+ def test_testcase_get_ci_loop(self):
+ self.assertEqual(self.tier.get_ci_loop(), 'test_ci_loop')
def test_dependency_get_installer(self):
- self.assertEqual(self.dependency.get_installer(),
- 'test_installer')
+ self.assertEqual(self.dependency.get_installer(), 'test_installer')
def test_dependency_get_scenario(self):
- self.assertEqual(self.dependency.get_scenario(),
- 'test_scenario')
+ self.assertEqual(self.dependency.get_scenario(), 'test_scenario')
if __name__ == "__main__":
diff --git a/tox.ini b/tox.ini
index 70621618a..0dd543dab 100644
--- a/tox.ini
+++ b/tox.ini
@@ -34,8 +34,9 @@ modules =
functest.core
functest.energy
functest.opnfv_tests.sdn.odl
- functest.tests.unit.ci.test_tier_handler
+ functest.tests.unit.ci.test_check_deployment
functest.tests.unit.ci.test_tier_builder
+ functest.tests.unit.ci.test_tier_handler
functest.tests.unit.core
functest.tests.unit.energy
functest.tests.unit.odl
@@ -70,11 +71,15 @@ commands = nosetests {[testenv:py35]dirs}
[testenv:cover]
basepython = python2.7
dirs =
+ functest/tests/unit/ci
functest/tests/unit/core
functest/tests/unit/energy
functest/tests/unit/odl
functest/tests/unit/utils/test_decorators.py
commands = nosetests --with-coverage --cover-tests \
+ --cover-package functest.ci.check_deployment \
+ --cover-package functest.ci.tier_builder \
+ --cover-package functest.ci.tier_handler \
--cover-package functest.core \
--cover-package functest.energy \
--cover-package functest.opnfv_tests.sdn.odl \