diff options
Diffstat (limited to 'dovetail/tests/unit/utils/test_dovetail_utils.py')
-rw-r--r-- | dovetail/tests/unit/utils/test_dovetail_utils.py | 40 |
1 files changed, 28 insertions, 12 deletions
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) |