Skip to content

Instantly share code, notes, and snippets.

@RyanKor
Created October 15, 2021 11:14
Show Gist options
  • Save RyanKor/d446b654e711761836e3e105040ae78e to your computer and use it in GitHub Desktop.
Save RyanKor/d446b654e711761836e3e105040ae78e to your computer and use it in GitHub Desktop.
task_id = "53326486-2089-4679-8d24-0b09192ad2d8"
task_owner = "1565f71789534d35b188781d7ec3e30e"
task_type = "import"
task_status = "pending"
TASK = {
'id': task_id,
'type': task_type,
'owner': task_owner,
'status': task_status,
}
class TestTaskv2(utils.TestCommand):
def setUp(self):
super(TestTaskv2, self).setUp()
self.app.client_manager.image = FakeImagev2Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,
)
self.app.client_manager.identity = identity_fakes.FakeIdentityv3Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,
)
class FakeTask(object):
"""Fake one or more tasks.
TODO(lsmman): Currently, only image API v2 is supported by this class.
"""
@staticmethod
def create_one_task(attrs=None):
"""Create a fake image.
:param Dictionary attrs:
A dictionary with all attrbutes of image
:return:
A FakeResource object with id, name, owner, protected,
visibility, tags and size attrs
"""
attrs = attrs or {}
# Set default attribute
task_info = {
'id': task_id,
'type': task_type,
'owner': task_owner,
'status': task_status,
}
# Overwrite default attributes if there are some attributes set
task_info.update(attrs)
return task.Task(**task_info)
@staticmethod
def create_tasks(attrs=None, count=2):
"""Create multiple fake images.
:param Dictionary attrs:
A dictionary with all attributes of image
:param Integer count:
The number of images to be faked
:return:
A list of FakeResource objects
"""
tasks = []
for n in range(0, count):
tasks.append(FakeTask.create_one_task(attrs))
return tasks
@staticmethod
def get_task(tasks=None, count=2):
"""Create a fake task.
:param Dictionary attrs:
A dictionary with all attributes of task
:return:
A FakeResource object with id, type and owner attrs
"""
if tasks is None:
tasks = FakeTask.create_tasks(count)
return mock.Mock(side_effect=tasks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment