From 58667cba215c2cb999d6bcaf891980bda4325b42 Mon Sep 17 00:00:00 2001 From: Morgan Richomme Date: Wed, 24 May 2017 17:00:49 +0200 Subject: Refactor core VNF class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Simplify processing - Implement run method to inherit testcase methods - Add unit tests - Fix all pylint issues It also obliges vnf and its uts to be rated 10/10 by pylint. JIRA: FUNCTEST-830 Co-Authored-By: Cédric Ollivier Change-Id: I8dd24eea55089277c9e5b2b51fb14dc377f2fcaf Signed-off-by: Morgan Richomme Signed-off-by: Cédric Ollivier --- functest/tests/unit/utils/test_openstack_utils.py | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'functest/tests/unit/utils/test_openstack_utils.py') diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py index 15b54057..0f06b1e1 100644 --- a/functest/tests/unit/utils/test_openstack_utils.py +++ b/functest/tests/unit/utils/test_openstack_utils.py @@ -1835,6 +1835,77 @@ class OSUtilsTesting(unittest.TestCase): None) self.assertTrue(mock_logger_error.called) + def test_get_or_create_user_for_vnf_get(self): + with mock.patch('functest.utils.openstack_utils.' + 'get_user_id', + return_value='user_id'), \ + mock.patch('functest.utils.openstack_utils.get_tenant_id', + return_value='tenant_id'): + self.assertFalse(openstack_utils. + get_or_create_user_for_vnf(self.keystone_client, + 'my_vnf')) + + def test_get_or_create_user_for_vnf_create(self): + with mock.patch('functest.utils.openstack_utils.' + 'get_user_id', + return_value=None), \ + mock.patch('functest.utils.openstack_utils.get_tenant_id', + return_value='tenant_id'): + self.assertTrue(openstack_utils. + get_or_create_user_for_vnf(self.keystone_client, + 'my_vnf')) + + def test_get_or_create_user_for_vnf_error_get_user_id(self): + with mock.patch('functest.utils.openstack_utils.' + 'get_user_id', + side_effect=Exception): + self.assertRaises(Exception) + + def test_get_or_create_user_for_vnf_error_get_tenant_id(self): + with mock.patch('functest.utils.openstack_utils.' + 'get_user_id', + return_value='user_id'), \ + mock.patch('functest.utils.openstack_utils.get_tenant_id', + side_effect='Exception'): + self.assertRaises(Exception) + + def test_get_or_create_tenant_for_vnf_get(self): + with mock.patch('functest.utils.openstack_utils.' + 'get_tenant_id', + return_value='tenant_id'): + self.assertFalse( + openstack_utils.get_or_create_tenant_for_vnf( + self.keystone_client, 'tenant_name', 'tenant_description')) + + def test_get_or_create_tenant_for_vnf_create(self): + with mock.patch('functest.utils.openstack_utils.get_tenant_id', + return_value=None): + self.assertTrue( + openstack_utils.get_or_create_tenant_for_vnf( + self.keystone_client, 'tenant_name', 'tenant_description')) + + def test_get_or_create_tenant_for_vnf_error_get_tenant_id(self): + with mock.patch('functest.utils.openstack_utils.' + 'get_tenant_id', + side_effect=Exception): + self.assertRaises(Exception) + + def test_download_and_add_image_on_glance_image_creation_failure(self): + with mock.patch('functest.utils.openstack_utils.' + 'os.makedirs'), \ + mock.patch('functest.utils.openstack_utils.' + 'ft_utils.download_url', + return_value=True), \ + mock.patch('functest.utils.openstack_utils.' + 'create_glance_image', + return_value=''): + resp = openstack_utils.download_and_add_image_on_glance( + self.glance_client, + 'image_name', + 'http://url', + 'data_dir') + self.assertEqual(resp, False) + if __name__ == "__main__": logging.disable(logging.CRITICAL) -- cgit 1.2.3-korg