1818
1919from openstack .image .v2 import image
2020from openstack .image .v2 import member
21+ from openstack .image .v2 import task
2122
2223from openstackclient .tests .unit import fakes
2324from openstackclient .tests .unit .identity .v3 import fakes as identity_fakes
@@ -44,6 +45,9 @@ def __init__(self, **kwargs):
4445
4546 self .remove_tag = mock .Mock ()
4647
48+ self .tasks = mock .Mock ()
49+ self .get_task = mock .Mock ()
50+
4751 self .auth_token = kwargs ['token' ]
4852 self .management_url = kwargs ['endpoint' ]
4953 self .version = 2.0
@@ -129,3 +133,53 @@ def create_one_image_member(attrs=None):
129133 image_member_info .update (attrs )
130134
131135 return member .Member (** image_member_info )
136+
137+
138+ def create_one_task (attrs = None ):
139+ """Create a fake task.
140+
141+ :param attrs: A dictionary with all attributes of task
142+ :type attrs: dict
143+ :return: A fake Task object.
144+ :rtype: `openstack.image.v2.task.Task`
145+ """
146+ attrs = attrs or {}
147+
148+ # Set default attribute
149+ task_info = {
150+ 'created_at' : '2016-06-29T16:13:07Z' ,
151+ 'expires_at' : '2016-07-01T16:13:07Z' ,
152+ 'id' : str (uuid .uuid4 ()),
153+ 'input' : {
154+ 'image_properties' : {
155+ 'container_format' : 'ovf' ,
156+ 'disk_format' : 'vhd'
157+ },
158+ 'import_from' : 'https://apps.openstack.org/excellent-image' ,
159+ 'import_from_format' : 'qcow2'
160+ },
161+ 'message' : '' ,
162+ 'owner' : str (uuid .uuid4 ()),
163+ 'result' : {
164+ 'image_id' : str (uuid .uuid4 ()),
165+ },
166+ 'schema' : '/v2/schemas/task' ,
167+ 'status' : random .choice (
168+ [
169+ 'pending' ,
170+ 'processing' ,
171+ 'success' ,
172+ 'failure' ,
173+ ]
174+ ),
175+ # though not documented, the API only allows 'import'
176+ # https://github.com/openstack/glance/blob/24.0.0/glance/api/v2/tasks.py#L186-L190
177+ 'type' : 'import' ,
178+ 'updated_at' : '2016-06-29T16:13:07Z' ,
179+
180+ }
181+
182+ # Overwrite default attributes if there are some attributes set
183+ task_info .update (attrs )
184+
185+ return task .Task (** task_info )
0 commit comments