diff options
-rw-r--r-- | functest/tests/unit/core/test_vnf.py | 68 | ||||
-rw-r--r-- | functest/tests/unit/odl/test_odl.py | 3 | ||||
-rw-r--r-- | tox.ini | 15 |
3 files changed, 77 insertions, 9 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() diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py index a331a6f3..ff25cd7a 100644 --- a/functest/tests/unit/odl/test_odl.py +++ b/functest/tests/unit/odl/test_odl.py @@ -178,9 +178,6 @@ class ODLMainTesting(ODLTesting): report='NONE', stdout=mock.ANY, variable=variable) - if len(args) > 2: - args[2].assert_called_with( - os.path.join(self.test.res_dir, 'stdout.txt')) def _test_no_keyword(self, key): kwargs = self._get_run_suites_kwargs(key) @@ -1,5 +1,5 @@ [tox] -envlist = docs,pep8,pylint,py35,py27,perm +envlist = docs,pep8,pylint,py35,py27,perm,cover [testenv] usedevelop = True @@ -49,6 +49,19 @@ dirs = functest/tests/unit/utils/test_decorators.py commands = nosetests {[testenv:py35]dirs} +[testenv:cover] +basepython = python2.7 +dirs = + functest/tests/unit/core + functest/tests/unit/odl + functest/tests/unit/utils/test_decorators.py +commands = nosetests --with-coverage --cover-tests \ + --cover-package functest.core \ + --cover-package functest.opnfv_tests.sdn.odl \ + --cover-package functest.tests.unit \ + --cover-package functest.utils.decorators \ + --cover-min-percentage 100 {[testenv:cover]dirs} + [testenv:perm] basepython = python2.7 whitelist_externals = bash |