summaryrefslogtreecommitdiff
path: root/glanceclient/tests/unit/v2/test_shell_v2.py
diff options
context:
space:
mode:
Diffstat (limited to 'glanceclient/tests/unit/v2/test_shell_v2.py')
-rw-r--r--glanceclient/tests/unit/v2/test_shell_v2.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py
index 3f1d77a..c2aa58a 100644
--- a/glanceclient/tests/unit/v2/test_shell_v2.py
+++ b/glanceclient/tests/unit/v2/test_shell_v2.py
@@ -113,6 +113,7 @@ class ShellV2Test(testtools.TestCase):
utils.print_list = mock.Mock()
utils.print_dict = mock.Mock()
utils.save_image = mock.Mock()
+ utils.print_dict_list = mock.Mock()
def assert_exits_with_msg(self, func, func_args, err_msg=None):
with mock.patch.object(utils, 'exit') as mocked_utils_exit:
@@ -562,6 +563,57 @@ class ShellV2Test(testtools.TestCase):
'size': 1024},
max_column_width=120)
+ def _test_do_image_tasks(self, verbose=False, supported=True):
+ args = self._make_args({'id': 'pass', 'verbose': verbose})
+ expected_columns = ["Message", "Status", "Updated at"]
+ expected_output = {
+ "tasks": [
+ {
+ "image_id": "pass",
+ "id": "task_1",
+ "user_id": "user_1",
+ "request_id": "request_id_1",
+ "message": "fake_message",
+ "status": "status",
+ }
+ ]
+ }
+
+ if verbose:
+ columns_to_prepend = ['Image Id', 'Task Id']
+ columns_to_extend = ['User Id', 'Request Id',
+ 'Result', 'Owner', 'Input', 'Expires at']
+ expected_columns = (columns_to_prepend + expected_columns +
+ columns_to_extend)
+ expected_output["tasks"][0]["Result"] = "Fake Result"
+ expected_output["tasks"][0]["Owner"] = "Fake Owner"
+ expected_output["tasks"][0]["Input"] = "Fake Input"
+ expected_output["tasks"][0]["Expires at"] = "Fake Expiry"
+
+ with mock.patch.object(self.gc.images,
+ 'get_associated_image_tasks') as mocked_tasks:
+ if supported:
+ mocked_tasks.return_value = expected_output
+ else:
+ mocked_tasks.side_effect = exc.HTTPNotImplemented
+ test_shell.do_image_tasks(self.gc, args)
+ mocked_tasks.assert_called_once_with('pass')
+ if supported:
+ utils.print_dict_list.assert_called_once_with(
+ expected_output['tasks'], expected_columns)
+
+ def test_do_image_tasks_without_verbose(self):
+ self._test_do_image_tasks()
+
+ def test_do_image_tasks_with_verbose(self):
+ self._test_do_image_tasks(verbose=True)
+
+ def test_do_image_tasks_unsupported(self):
+ with mock.patch('glanceclient.common.utils.exit') as mock_exit:
+ self._test_do_image_tasks(supported=False)
+ mock_exit.assert_called_once_with(
+ 'Server does not support image tasks API (v2.12)')
+
@mock.patch('sys.stdin', autospec=True)
def test_do_image_create_no_user_props(self, mock_stdin):
args = self._make_args({'name': 'IMG-01', 'disk_format': 'vhd',