summaryrefslogtreecommitdiffstats
path: root/dovetail/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'dovetail/tests/unit')
-rw-r--r--dovetail/tests/unit/test_container.py30
-rw-r--r--dovetail/tests/unit/test_report.py39
-rw-r--r--dovetail/tests/unit/test_test_runner.py12
-rw-r--r--dovetail/tests/unit/utils/test_dovetail_utils.py40
4 files changed, 95 insertions, 26 deletions
diff --git a/dovetail/tests/unit/test_container.py b/dovetail/tests/unit/test_container.py
index 01c1d8fd..86da9d3c 100644
--- a/dovetail/tests/unit/test_container.py
+++ b/dovetail/tests/unit/test_container.py
@@ -409,6 +409,7 @@ class ContainerTesting(unittest.TestCase):
container_id = 'container_id'
mock_utils.get_value_from_dict.side_effect = [
{'key': 'value'}, 'shell', 'envs', ['volume_one', 'volume_two']]
+ mock_utils.get_mount_list.side_effect = [['mount', 'list'], 'success']
mock_utils.get_hosts_info.return_value = 'host_info'
container_obj = Mock()
container_obj.id = container_id
@@ -417,7 +418,7 @@ class ContainerTesting(unittest.TestCase):
mock_config.dovetail_config = {'bottlenecks': project_config}
expected = container_id
- result = self.container.create(docker_image)
+ result, msg = self.container.create(docker_image)
mock_utils.get_value_from_dict.assert_has_calls([
call('opts', project_config),
@@ -426,6 +427,7 @@ class ContainerTesting(unittest.TestCase):
call('volumes', project_config)])
mock_utils.get_hosts_info.assert_called_once_with(self.logger)
self.assertEqual(expected, result)
+ self.assertEqual('Successfully to create container.', msg)
@patch('dovetail.container.dt_utils')
@patch('dovetail.container.dt_cfg')
@@ -435,12 +437,32 @@ class ContainerTesting(unittest.TestCase):
mock_utils.get_value_from_dict.side_effect = ['opts', None]
mock_utils.get_hosts_info.return_value = 'host_info'
- result = self.container.create(docker_image)
+ result, msg = self.container.create(docker_image)
mock_utils.get_value_from_dict.assert_has_calls([
call('opts', 'value'),
call('shell', 'value')])
self.assertEqual(None, result)
+ self.assertEqual("Lacking of key word 'shell' in config file.", msg)
+
+ @patch('dovetail.container.dt_utils')
+ @patch('dovetail.container.dt_cfg')
+ def test_create_mounts_none(self, mock_config, mock_utils):
+ docker_image = 'docker_image'
+ project_config = {}
+ mock_config.dovetail_config = {'bottlenecks': project_config}
+ mock_utils.get_value_from_dict.side_effect = [
+ {'key': 'value'}, 'shell', ['envs'], ['volume_one']]
+ mock_utils.get_mount_list.side_effect = [[None, 'error']]
+ mock_utils.get_hosts_info.return_value = 'host_info'
+
+ result, msg = self.container.create(docker_image)
+
+ mock_utils.get_value_from_dict.assert_has_calls([
+ call('opts', project_config), call('shell', project_config),
+ call('envs', project_config), call('volumes', project_config)])
+ self.assertEqual(None, result)
+ self.assertEqual('error', msg)
@patch('dovetail.container.dt_utils')
@patch('dovetail.container.dt_cfg')
@@ -448,13 +470,14 @@ class ContainerTesting(unittest.TestCase):
docker_image = 'docker_image'
mock_utils.get_value_from_dict.side_effect = [
{'key': 'value'}, 'shell', ['envs'], ['volume_one']]
+ mock_utils.get_mount_list.side_effect = [['mount', 'list'], 'success']
mock_utils.get_hosts_info.return_value = 'host_info'
mock_utils.check_https_enabled.return_value = True
self.client.containers.run.side_effect = \
docker.errors.ImageNotFound('error')
project_config = {}
mock_config.dovetail_config = {'bottlenecks': project_config}
- result = self.container.create(docker_image)
+ result, msg = self.container.create(docker_image)
mock_utils.get_value_from_dict.assert_has_calls([
call('opts', project_config),
@@ -463,3 +486,4 @@ class ContainerTesting(unittest.TestCase):
call('volumes', project_config)])
mock_utils.get_hosts_info.assert_called_once_with(self.logger)
self.assertEqual(None, result)
+ self.assertEqual('error', str(docker.errors.ImageNotFound('error')))
diff --git a/dovetail/tests/unit/test_report.py b/dovetail/tests/unit/test_report.py
index fe6530c9..41d70d2f 100644
--- a/dovetail/tests/unit/test_report.py
+++ b/dovetail/tests/unit/test_report.py
@@ -640,6 +640,28 @@ class ReportTesting(unittest.TestCase):
'Result file not found: {}'.format(file_path))
self.assertEqual(None, result)
+ def test_functest_crawler_get_details_exception(self):
+ logger_obj = Mock()
+ dt_report.FunctestCrawler.logger = logger_obj
+ data = None
+ crawler = dt_report.FunctestCrawler()
+
+ excepted = None
+ result = crawler.get_details(data)
+ logger_obj.exception.assert_called_once()
+ self.assertEqual(excepted, result)
+
+ def test_functest_crawler_get_rally_details_exception(self):
+ logger_obj = Mock()
+ dt_report.FunctestCrawler.logger = logger_obj
+ data = None
+ crawler = dt_report.FunctestCrawler()
+
+ excepted = None
+ result = crawler.get_rally_details(data)
+ logger_obj.exception.assert_called_once()
+ self.assertEqual(excepted, result)
+
@patch('builtins.open')
@patch('dovetail.report.json')
@patch('dovetail.report.dt_cfg')
@@ -719,12 +741,17 @@ class ReportTesting(unittest.TestCase):
'criteria': 'criteria',
'start_date': 'start_date',
'stop_date': 'stop_date',
- 'details': [{
- 'details': {
- 'success': ['subt_a'],
- 'failures': ['subt_b', 'subt_c']
- }
- }]
+ 'details': {
+ 'modules': [
+ {
+ 'details': {
+ 'success': ['subt_a'],
+ 'failures': ['subt_b', 'subt_c']
+ },
+ 'module': 'module'
+ }
+ ]
+ }
}
mock_json.loads.return_value = data_dict
diff --git a/dovetail/tests/unit/test_test_runner.py b/dovetail/tests/unit/test_test_runner.py
index 3cb27536..232de7b1 100644
--- a/dovetail/tests/unit/test_test_runner.py
+++ b/dovetail/tests/unit/test_test_runner.py
@@ -107,7 +107,7 @@ class TestRunnerTesting(unittest.TestCase):
docker_img_obj = Mock()
container_obj.get_docker_image.return_value = docker_img_obj
container_obj.pull_image.return_value = True
- container_obj.create.return_value = False
+ container_obj.create.return_value = [None, 'error']
mock_container.return_value = container_obj
docker_runner.run()
@@ -116,8 +116,8 @@ class TestRunnerTesting(unittest.TestCase):
container_obj.get_docker_image.assert_called_once_with()
container_obj.pull_image.assert_called_once_with(docker_img_obj)
container_obj.create.assert_called_once_with(docker_img_obj)
- docker_runner.logger.error.assert_called_once_with(
- 'Failed to create container.')
+ docker_runner.logger.error.assert_has_calls([
+ call('Failed to create container.'), call('error')])
@patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.dt_cfg')
@@ -137,7 +137,8 @@ class TestRunnerTesting(unittest.TestCase):
container_obj.get_docker_image.return_value = docker_img_obj
container_obj.pull_image.return_value = True
container_id = '12345'
- container_obj.create.return_value = container_id
+ container_msg = 'Successfully to create container.'
+ container_obj.create.return_value = [container_id, container_msg]
mock_container.return_value = container_obj
self.testcase.pre_condition.return_value = ['cmd']
self.testcase.prepare_cmd.return_value = False
@@ -180,7 +181,8 @@ class TestRunnerTesting(unittest.TestCase):
container_obj.get_docker_image.return_value = docker_img_obj
container_obj.pull_image.return_value = True
container_id = '12345'
- container_obj.create.return_value = container_id
+ container_msg = 'Successfully to create container.'
+ container_obj.create.return_value = [container_id, container_msg]
mock_container.return_value = container_obj
self.testcase.pre_condition.return_value = ['cmd']
self.testcase.prepare_cmd.return_value = True
diff --git a/dovetail/tests/unit/utils/test_dovetail_utils.py b/dovetail/tests/unit/utils/test_dovetail_utils.py
index 5b403a5c..7d1fddc1 100644
--- a/dovetail/tests/unit/utils/test_dovetail_utils.py
+++ b/dovetail/tests/unit/utils/test_dovetail_utils.py
@@ -510,15 +510,12 @@ class DovetailUtilsTesting(unittest.TestCase):
hosts_obj.add.assert_called_once_with([entry_obj])
hosts_obj.write.assert_called_once()
- @patch('dovetail.utils.dovetail_utils.objwalk')
- def test_get_obj_by_path(self, mock_walk):
- path = dist_path = 'path'
- obj = 'obj'
- mock_walk.return_value = [(path, obj)]
-
- expected = obj
- result = dovetail_utils.get_obj_by_path(obj, dist_path)
+ def test_get_obj_by_path(self):
+ obj = {'list': ['a', 'b'], 'name': 'name'}
+ dst_path = ('name',)
+ expected = 'name'
+ result = dovetail_utils.get_obj_by_path(obj, dst_path)
self.assertEqual(expected, result)
@patch('dovetail.utils.dovetail_utils.objwalk')
@@ -1233,9 +1230,9 @@ class DovetailUtilsTesting(unittest.TestCase):
subp_stdout = Mock()
subprocess_obj.stdout = subp_stdout
subprocess_obj.wait.return_value = 0
- subp_stdout.readline.side_effect = [cmd_output, '']
+ subp_stdout.readline.side_effect = [cmd_output.encode()]
- expected = (0, 'line')
+ expected = (0, "b'line'")
result = dovetail_utils.exec_cmd(
cmd, logger=logger, exit_on_error=True, info=False,
exec_msg_on=True, err_msg='', verbose=verbose,
@@ -1276,7 +1273,7 @@ class DovetailUtilsTesting(unittest.TestCase):
subp_stdout = Mock()
subprocess_obj.stdout = subp_stdout
subprocess_obj.wait.return_value = 1
- subp_stdout.readline.side_effect = [cmd_output, '']
+ subp_stdout.readline.side_effect = [cmd_output.encode()]
dovetail_utils.exec_cmd(
cmd, logger=logger, exit_on_error=True, info=False,
@@ -1286,7 +1283,6 @@ class DovetailUtilsTesting(unittest.TestCase):
log_calls = [
call(verbose, logger, "Executing command: '%s'" % cmd, 'debug'),
call(verbose, logger, cmd_output, 'debug', True),
- call(verbose, logger, '', 'debug', True),
call(verbose, logger, "The command '%s' failed." % cmd, 'error')]
mock_log.assert_has_calls(log_calls)
mock_open.assert_called_once_with(cmd, shell=True, stdout=mock_pipe,
@@ -1384,3 +1380,23 @@ class DovetailUtilsTesting(unittest.TestCase):
logger.debug.assert_not_called()
logger.exception.assert_called_once_with(
"The results cannot be pushed to DB.")
+
+ def test_get_mount_list_error_mount(self):
+ project_cfg = {'mounts': ['aaa']}
+ res, msg = dovetail_utils.get_mount_list(project_cfg)
+ self.assertEqual(None, res)
+ self.assertEqual('Error mount aaa.', msg)
+
+ def test_get_mount_list_keyerror_exception(self):
+ project_cfg = {'mounts': ['aaa=a,bbb=b', '']}
+ res, msg = dovetail_utils.get_mount_list(project_cfg)
+ self.assertEqual(None, res)
+ self.assertEqual("'target'", str(msg))
+
+ def test_get_mount_list(self):
+ project_cfg = {'mounts': ['target=a,source=b', '']}
+ res, msg = dovetail_utils.get_mount_list(project_cfg)
+ expected = [{'Source': 'b', 'Type': 'bind', 'ReadOnly': False,
+ 'Target': 'a'}]
+ self.assertEqual(expected, res)
+ self.assertEqual('Successfully to get mount list.', msg)