@@ -434,3 +434,77 @@ def setUp(self):
434434 endpoint = fakes .AUTH_URL ,
435435 token = fakes .AUTH_TOKEN ,
436436 )
437+
438+
439+ class FakeType (object ):
440+ """Fake one or more type."""
441+
442+ @staticmethod
443+ def create_one_type (attrs = None , methods = None ):
444+ """Create a fake type.
445+
446+ :param Dictionary attrs:
447+ A dictionary with all attributes
448+ :param Dictionary methods:
449+ A dictionary with all methods
450+ :return:
451+ A FakeResource object with id, name, description, etc.
452+ """
453+ attrs = attrs or {}
454+ methods = methods or {}
455+
456+ # Set default attributes.
457+ type_info = {
458+ "id" : 'type-id-' + uuid .uuid4 ().hex ,
459+ "name" : 'type-name-' + uuid .uuid4 ().hex ,
460+ "description" : 'type-description-' + uuid .uuid4 ().hex ,
461+ "extra_specs" : {"foo" : "bar" },
462+ "is_public" : True ,
463+ }
464+
465+ # Overwrite default attributes.
466+ type_info .update (attrs )
467+
468+ volume_type = fakes .FakeResource (
469+ info = copy .deepcopy (type_info ),
470+ methods = methods ,
471+ loaded = True )
472+ return volume_type
473+
474+ @staticmethod
475+ def create_types (attrs = None , count = 2 ):
476+ """Create multiple fake types.
477+
478+ :param Dictionary attrs:
479+ A dictionary with all attributes
480+ :param int count:
481+ The number of types to fake
482+ :return:
483+ A list of FakeResource objects faking the types
484+ """
485+ volume_types = []
486+ for i in range (0 , count ):
487+ volume_type = FakeType .create_one_type (attrs )
488+ volume_types .append (volume_type )
489+
490+ return volume_types
491+
492+ @staticmethod
493+ def get_types (types = None , count = 2 ):
494+ """Get an iterable MagicMock object with a list of faked types.
495+
496+ If types list is provided, then initialize the Mock object with the
497+ list. Otherwise create one.
498+
499+ :param List types:
500+ A list of FakeResource objects faking types
501+ :param Integer count:
502+ The number of types to be faked
503+ :return
504+ An iterable Mock object with side_effect set to a list of faked
505+ types
506+ """
507+ if types is None :
508+ types = FakeType .create_types (count )
509+
510+ return mock .MagicMock (side_effect = types )
0 commit comments