aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit/utils
diff options
context:
space:
mode:
Diffstat (limited to 'functest/tests/unit/utils')
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py41
-rw-r--r--functest/tests/unit/utils/test_openstack_utils.py71
2 files changed, 75 insertions, 37 deletions
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index d84a3201..98c7d6e9 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -8,11 +8,11 @@
# http://www.apache.org/licenses/LICENSE-2.0
import logging
+import pkg_resources
import os
import time
import unittest
-from git.exc import NoSuchPathError
import mock
import requests
from six.moves import urllib
@@ -56,8 +56,8 @@ class FunctestUtilsTesting(unittest.TestCase):
self.testcase_dict = {'case_name': 'testname',
'criteria': self.criteria}
self.parameter = 'general.openstack.image_name'
- self.config_yaml = os.path.normpath(os.path.join(os.path.dirname(
- os.path.abspath(__file__)), '../../../ci/config_functest.yaml'))
+ self.config_yaml = pkg_resources.resource_filename(
+ 'functest', 'ci/config_functest.yaml')
self.db_url_env = 'http://foo/testdb'
self.testcases_yaml = "test_testcases_yaml"
self.file_yaml = {'general': {'openstack': {'image_name':
@@ -97,27 +97,6 @@ class FunctestUtilsTesting(unittest.TestCase):
m.assert_called_once_with(dest, 'wb')
self.assertTrue(mock_sh.called)
- def test_get_git_branch(self):
- with mock.patch('functest.utils.functest_utils.Repo') as mock_repo:
- mock_obj2 = mock.Mock()
- attrs = {'name': 'test_branch'}
- mock_obj2.configure_mock(**attrs)
-
- mock_obj = mock.Mock()
- attrs = {'active_branch': mock_obj2}
- mock_obj.configure_mock(**attrs)
-
- mock_repo.return_value = mock_obj
- self.assertEqual(functest_utils.get_git_branch(self.repo_path),
- 'test_branch')
-
- @mock.patch('functest.utils.functest_utils.Repo',
- side_effect=NoSuchPathError)
- def test_get_git_branch_failed(self, mock_repo):
- self.assertRaises(NoSuchPathError,
- lambda: functest_utils.get_git_branch(self.repo_path
- ))
-
@mock.patch('functest.utils.functest_utils.logger.error')
def test_get_installer_type_failed(self, mock_logger_error):
with mock.patch.dict(os.environ,
@@ -486,9 +465,7 @@ class FunctestUtilsTesting(unittest.TestCase):
def test_get_dict_by_test(self, mock_logger_error):
with mock.patch('six.moves.builtins.open', mock.mock_open()), \
mock.patch('functest.utils.functest_utils.yaml.safe_load') \
- as mock_yaml, \
- mock.patch('functest.utils.functest_utils.get_testcases_'
- 'file_dir'):
+ as mock_yaml:
mock_obj = mock.Mock()
attrs = {'get.return_value': [{'testcases': [self.testcase_dict]}]}
mock_obj.configure_mock(**attrs)
@@ -542,16 +519,6 @@ class FunctestUtilsTesting(unittest.TestCase):
assert_called_once_with(self.parameter,
self.config_yaml)
- # TODO: merge_dicts
-
- @mock.patch('functest.utils.functest_utils.get_functest_config')
- def test_get_testcases_file_dir(self, mock_get_functest_config):
- mock_get_functest_config.return_value = self.testcases_yaml
- resp = functest_utils.get_testcases_file_dir()
- self.assertEqual(resp, self.testcases_yaml)
- mock_get_functest_config.assert_called_once_with(
- 'general.functest.testcases_yaml')
-
def test_get_functest_yaml(self):
with mock.patch('six.moves.builtins.open', mock.mock_open()), \
mock.patch('functest.utils.functest_utils.yaml.safe_load') \
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)