<s> from tests . compat import unittest <EOL> from tests . unit import AWSMockServiceTestCase <EOL> from boto . ec2 . connection import EC2Connection <EOL> from boto . ec2 . securitygroup import SecurityGroup <EOL> DESCRIBE_SECURITY_GROUP = br"""<STR_LIT>""" <EOL> DESCRIBE_INSTANCES = br"""<STR_LIT>""" <EOL> class TestDescribeSecurityGroups ( AWSMockServiceTestCase ) : <EOL> connection_class = EC2Connection <EOL> def test_get_instances ( self ) : <EOL> self . set_http_response ( status_code = <NUM_LIT:200> , body = DESCRIBE_SECURITY_GROUP ) <EOL> groups = self . service_connection . get_all_security_groups ( ) <EOL> self . set_http_response ( status_code = <NUM_LIT:200> , body = DESCRIBE_INSTANCES ) <EOL> instances = groups [ <NUM_LIT:0> ] . instances ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( instances ) ) <EOL> self . assertEqual ( groups [ <NUM_LIT:0> ] . id , instances [ <NUM_LIT:0> ] . groups [ <NUM_LIT:0> ] . id ) <EOL> class SecurityGroupTest ( unittest . TestCase ) : <EOL> def test_add_rule ( self ) : <EOL> sg = SecurityGroup ( ) <EOL> self . assertEqual ( len ( sg . rules ) , <NUM_LIT:0> ) <EOL> sg . add_rule ( <EOL> ip_protocol = '<STR_LIT:http>' , <EOL> from_port = '<STR_LIT>' , <EOL> to_port = '<STR_LIT>' , <EOL> src_group_name = '<STR_LIT>' , <EOL> src_group_owner_id = '<STR_LIT>' , <EOL> cidr_ip = '<STR_LIT>' , <EOL> src_group_group_id = '<STR_LIT>' , <EOL> dry_run = False <EOL> ) <EOL> self . assertEqual ( len ( sg . rules ) , <NUM_LIT:1> ) <EOL> def test_remove_rule_on_empty_group ( self ) : <EOL> sg = SecurityGroup ( ) <EOL> with self . assertRaises ( ValueError ) : <EOL> sg . remove_rule ( '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , None , None , None , None ) </s>
