@@ -463,28 +463,76 @@ def create_security_groups(attrs={}, methods={}, count=2):
463463 security_groups = []
464464 for i in range (0 , count ):
465465 security_groups .append (
466- FakeRouter .create_one_security_group (attrs , methods ))
466+ FakeSecurityGroup .create_one_security_group (attrs , methods ))
467467
468468 return security_groups
469469
470+
471+ class FakeSecurityGroupRule (object ):
472+ """Fake one or more security group rules."""
473+
470474 @staticmethod
471- def get_security_groups (security_groups = None , count = 2 ):
472- """Get an iterable MagicMock object with a list of faked security groups.
475+ def create_one_security_group_rule (attrs = {}, methods = {}):
476+ """Create a fake security group rule.
477+
478+ :param Dictionary attrs:
479+ A dictionary with all attributes
480+ :param Dictionary methods:
481+ A dictionary with all methods
482+ :return:
483+ A FakeResource object, with id, name, etc.
484+ """
485+ # Set default attributes.
486+ security_group_rule_attrs = {
487+ 'description' : 'security-group-rule-desc-' + uuid .uuid4 ().hex ,
488+ 'direction' : 'ingress' ,
489+ 'ethertype' : 'IPv4' ,
490+ 'id' : 'security-group-rule-id-' + uuid .uuid4 ().hex ,
491+ 'name' : 'security-group-rule-name-' + uuid .uuid4 ().hex ,
492+ 'port_range_max' : None ,
493+ 'port_range_min' : None ,
494+ 'protocol' : None ,
495+ 'remote_group_id' : 'remote-security-group-id-' + uuid .uuid4 ().hex ,
496+ 'remote_ip_prefix' : None ,
497+ 'security_group_id' : 'security-group-id-' + uuid .uuid4 ().hex ,
498+ 'tenant_id' : 'project-id-' + uuid .uuid4 ().hex ,
499+ }
500+
501+ # Overwrite default attributes.
502+ security_group_rule_attrs .update (attrs )
473503
474- If security group list is provided, then initialize the Mock object
475- with the list. Otherwise create one.
504+ # Set default methods.
505+ security_group_rule_methods = {}
506+
507+ # Overwrite default methods.
508+ security_group_rule_methods .update (methods )
509+
510+ security_group_rule = fakes .FakeResource (
511+ info = copy .deepcopy (security_group_rule_attrs ),
512+ methods = copy .deepcopy (security_group_rule_methods ),
513+ loaded = True )
514+ return security_group_rule
515+
516+ @staticmethod
517+ def create_security_group_rules (attrs = {}, methods = {}, count = 2 ):
518+ """Create multiple fake security group rules.
476519
477- :param List security groups:
478- A list of FakeResource objects faking security groups
520+ :param Dictionary attrs:
521+ A dictionary with all attributes
522+ :param Dictionary methods:
523+ A dictionary with all methods
479524 :param int count:
480- The number of security groups to fake
525+ The number of security group rules to fake
481526 :return:
482- An iterable Mock object with side_effect set to a list of faked
483- security groups
527+ A list of FakeResource objects faking the security group rules
484528 """
485- if security_groups is None :
486- security_groups = FakeRouter .create_security_groups (count )
487- return mock .MagicMock (side_effect = security_groups )
529+ security_group_rules = []
530+ for i in range (0 , count ):
531+ security_group_rules .append (
532+ FakeSecurityGroupRule .create_one_security_group_rule (
533+ attrs , methods ))
534+
535+ return security_group_rules
488536
489537
490538class FakeSubnet (object ):
0 commit comments