aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2017-11-29 06:16:46 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2017-11-29 06:20:10 +0100
commit2526db124832a9b9a51166b77159c6edaec9aa2a (patch)
treea205b04f51a49bffd7bd4ac9d8f3567eace4d521
parent726cab11430b12f303cd4ab5d5d383d21bee5c9a (diff)
Cover vnf.prepare()
It completes the previous commit [1] which increased the coverage of Vnf. [1] https://gerrit.opnfv.org/gerrit/#/c/47851/ Change-Id: Ibb0201d6165d89da2edd1a93b722008092726569 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/tests/unit/core/test_vnf.py68
1 files changed, 63 insertions, 5 deletions
diff --git a/functest/tests/unit/core/test_vnf.py b/functest/tests/unit/core/test_vnf.py
index 5ed6bb46..e0eee1a1 100644
--- a/functest/tests/unit/core/test_vnf.py
+++ b/functest/tests/unit/core/test_vnf.py
@@ -34,24 +34,38 @@ class VnfBaseTesting(unittest.TestCase):
"vnf_foo_tenant_description", self.tenant_description)
self.test = vnf.VnfOnBoarding(project='functest', case_name='foo')
+ def test_run_deploy_orch_exc(self):
+ with mock.patch.object(self.test, 'prepare'), \
+ mock.patch.object(self.test, 'deploy_orchestrator',
+ side_effect=Exception) as mock_method, \
+ mock.patch.object(self.test, 'deploy_vnf',
+ return_value=True), \
+ mock.patch.object(self.test, 'test_vnf',
+ return_value=True):
+ self.assertEqual(self.test.run(),
+ testcase.TestCase.EX_TESTCASE_FAILED)
+ mock_method.assert_called_with()
+
def test_run_deploy_vnf_exc(self):
with mock.patch.object(self.test, 'prepare'),\
mock.patch.object(self.test, 'deploy_orchestrator',
- return_value=None), \
+ return_value=True), \
mock.patch.object(self.test, 'deploy_vnf',
- side_effect=Exception):
+ side_effect=Exception) as mock_method:
self.assertEqual(self.test.run(),
testcase.TestCase.EX_TESTCASE_FAILED)
+ mock_method.assert_called_with()
def test_run_test_vnf_exc(self):
with mock.patch.object(self.test, 'prepare'),\
mock.patch.object(self.test, 'deploy_orchestrator',
- return_value=None), \
- mock.patch.object(self.test, 'deploy_vnf'), \
+ return_value=True), \
+ mock.patch.object(self.test, 'deploy_vnf', return_value=True), \
mock.patch.object(self.test, 'test_vnf',
- side_effect=Exception):
+ side_effect=Exception) as mock_method:
self.assertEqual(self.test.run(),
testcase.TestCase.EX_TESTCASE_FAILED)
+ mock_method.assert_called_with()
def test_run_deploy_orch_ko(self):
with mock.patch.object(self.test, 'prepare'),\
@@ -96,6 +110,50 @@ class VnfBaseTesting(unittest.TestCase):
return_value=True):
self.assertEqual(self.test.run(), testcase.TestCase.EX_OK)
+ @mock.patch('functest.core.vnf.OpenStackUser')
+ @mock.patch('functest.core.vnf.OpenStackProject')
+ @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials',
+ side_effect=Exception)
+ def test_prepare_exc1(self, *args):
+ with self.assertRaises(Exception):
+ self.test.prepare()
+ args[0].assert_called_with(
+ os_env_file=constants.CONST.__getattribute__('openstack_creds'))
+ args[1].assert_not_called()
+ args[2].assert_not_called()
+
+ @mock.patch('functest.core.vnf.OpenStackUser')
+ @mock.patch('functest.core.vnf.OpenStackProject', side_effect=Exception)
+ @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials')
+ def test_prepare_exc2(self, *args):
+ with self.assertRaises(Exception):
+ self.test.prepare()
+ args[0].assert_called_with(
+ os_env_file=constants.CONST.__getattribute__('openstack_creds'))
+ args[1].assert_called_with(mock.ANY, mock.ANY)
+ args[2].assert_not_called()
+
+ @mock.patch('functest.core.vnf.OpenStackUser', side_effect=Exception)
+ @mock.patch('functest.core.vnf.OpenStackProject')
+ @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials')
+ def test_prepare_exc3(self, *args):
+ with self.assertRaises(Exception):
+ self.test.prepare()
+ args[0].assert_called_with(
+ os_env_file=constants.CONST.__getattribute__('openstack_creds'))
+ args[1].assert_called_with(mock.ANY, mock.ANY)
+ args[2].assert_called_with(mock.ANY, mock.ANY)
+
+ @mock.patch('functest.core.vnf.OpenStackUser')
+ @mock.patch('functest.core.vnf.OpenStackProject')
+ @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials')
+ def test_prepare_default(self, *args):
+ self.assertEqual(self.test.prepare(), testcase.TestCase.EX_OK)
+ args[0].assert_called_with(
+ os_env_file=constants.CONST.__getattribute__('openstack_creds'))
+ args[1].assert_called_with(mock.ANY, mock.ANY)
+ args[2].assert_called_with(mock.ANY, mock.ANY)
+
def test_deploy_vnf_unimplemented(self):
with self.assertRaises(vnf.VnfDeploymentException):
self.test.deploy_vnf()