summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/image/v2/fakes.py
diff options
context:
space:
mode:
authorlsmman <lsmman07@gmail.com>2021-10-11 22:52:52 +0900
committerStephen Finucane <sfinucan@redhat.com>2022-09-21 10:34:15 +0100
commitd163a2090471c8f90c8ad84827fb97dfbf06280b (patch)
treeb066eca0e976bdc407da7339844a2bad83acde76 /openstackclient/tests/unit/image/v2/fakes.py
parent4024bdb3933dd79eec4bcf99c13f3dbf17add40b (diff)
downloadpython-openstackclient-d163a2090471c8f90c8ad84827fb97dfbf06280b.tar.gz
image: Add 'image task show' commands
This replaces and the 'glance task-show' command. For example: $ image task show <TASK_ID> Change-Id: I74cb23e436c373fe238804b903bbeb28f643d5af
Diffstat (limited to 'openstackclient/tests/unit/image/v2/fakes.py')
-rw-r--r--openstackclient/tests/unit/image/v2/fakes.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/image/v2/fakes.py b/openstackclient/tests/unit/image/v2/fakes.py
index a0eda6d2..2decd122 100644
--- a/openstackclient/tests/unit/image/v2/fakes.py
+++ b/openstackclient/tests/unit/image/v2/fakes.py
@@ -18,6 +18,7 @@ import uuid
from openstack.image.v2 import image
from openstack.image.v2 import member
+from openstack.image.v2 import task
from openstackclient.tests.unit import fakes
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
@@ -44,6 +45,9 @@ class FakeImagev2Client:
self.remove_tag = mock.Mock()
+ self.tasks = mock.Mock()
+ self.get_task = mock.Mock()
+
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']
self.version = 2.0
@@ -129,3 +133,53 @@ def create_one_image_member(attrs=None):
image_member_info.update(attrs)
return member.Member(**image_member_info)
+
+
+def create_one_task(attrs=None):
+ """Create a fake task.
+
+ :param attrs: A dictionary with all attributes of task
+ :type attrs: dict
+ :return: A fake Task object.
+ :rtype: `openstack.image.v2.task.Task`
+ """
+ attrs = attrs or {}
+
+ # Set default attribute
+ task_info = {
+ 'created_at': '2016-06-29T16:13:07Z',
+ 'expires_at': '2016-07-01T16:13:07Z',
+ 'id': str(uuid.uuid4()),
+ 'input': {
+ 'image_properties': {
+ 'container_format': 'ovf',
+ 'disk_format': 'vhd'
+ },
+ 'import_from': 'https://apps.openstack.org/excellent-image',
+ 'import_from_format': 'qcow2'
+ },
+ 'message': '',
+ 'owner': str(uuid.uuid4()),
+ 'result': {
+ 'image_id': str(uuid.uuid4()),
+ },
+ 'schema': '/v2/schemas/task',
+ 'status': random.choice(
+ [
+ 'pending',
+ 'processing',
+ 'success',
+ 'failure',
+ ]
+ ),
+ # though not documented, the API only allows 'import'
+ # https://github.com/openstack/glance/blob/24.0.0/glance/api/v2/tasks.py#L186-L190
+ 'type': 'import',
+ 'updated_at': '2016-06-29T16:13:07Z',
+
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ task_info.update(attrs)
+
+ return task.Task(**task_info)