@@ -605,3 +605,56 @@ def create_snapshots(attrs=None, count=2):
605605 snapshots .append (snapshot )
606606
607607 return snapshots
608+
609+
610+ class FakeType (object ):
611+ """Fake one or more type."""
612+
613+ @staticmethod
614+ def create_one_type (attrs = None , methods = None ):
615+ """Create a fake type.
616+
617+ :param Dictionary attrs:
618+ A dictionary with all attributes
619+ :param Dictionary methods:
620+ A dictionary with all methods
621+ :return:
622+ A FakeResource object with id, name, description, etc.
623+ """
624+ attrs = attrs or {}
625+ methods = methods or {}
626+
627+ # Set default attributes.
628+ type_info = {
629+ "id" : 'type-id-' + uuid .uuid4 ().hex ,
630+ "name" : 'type-name-' + uuid .uuid4 ().hex ,
631+ "description" : 'type-description-' + uuid .uuid4 ().hex ,
632+ "extra_specs" : {"foo" : "bar" },
633+ }
634+
635+ # Overwrite default attributes.
636+ type_info .update (attrs )
637+
638+ volume_type = fakes .FakeResource (
639+ info = copy .deepcopy (type_info ),
640+ methods = methods ,
641+ loaded = True )
642+ return volume_type
643+
644+ @staticmethod
645+ def create_types (attrs = None , count = 2 ):
646+ """Create multiple fake types.
647+
648+ :param Dictionary attrs:
649+ A dictionary with all attributes
650+ :param int count:
651+ The number of types to fake
652+ :return:
653+ A list of FakeResource objects faking the types
654+ """
655+ volume_types = []
656+ for i in range (0 , count ):
657+ volume_type = FakeType .create_one_type (attrs )
658+ volume_types .append (volume_type )
659+
660+ return volume_types
0 commit comments