def test_should_copy_ip_range_attribute_from_grant(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule().with_ip_range( '5.6.7.8/90').build() rule = self.ec2_rule_transformer.to_rule(ec2_rule) self.assertEqual(rule.ip_range, ec2_rule.grants[0].cidr_ip)
def test_should_return_false_if_rules_have_different_ip_range(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule()\ .with_ip_range('1.1.1.1/1')\ .build() self.assertFalse( self.rule_comparator.rules_are_equal(self.openstack_rule, ec2_rule))
def test_should_return_false_if_rules_have_different_from_ports(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule()\ .with_from_port(2222)\ .build() self.assertFalse( self.rule_comparator.rules_are_equal(self.openstack_rule, ec2_rule))
def test_should_return_true_if_rules_have_matching_ip_protocol_from_port_to_port_and_ip_range( self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule()\ .build() self.assertTrue( self.rule_comparator.rules_are_equal(self.openstack_rule, ec2_rule))
def test_should_return_false_if_rules_have_allowed_groups_with_different_names(self): self.openstack_rule["ip_range"] = {} self.openstack_rule["group"] = {"name": "secGroup"} self.ec2_connection.get_all_security_groups.return_value = [self.FakeSecurityGroup("secGroup2")] ec2_rule = FakeEC2RuleBuilder.an_ec2_rule().with_allowed_security_group_id(5).build() self.assertFalse(self.rule_comparator.rules_are_equal(self.openstack_rule, ec2_rule))
def test_should_set_group_name_from_grant(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule().with_allowed_security_group_id(123).build() ec2_group = Mock() ec2_group.name = 'secGroup' self.ec2_connection.get_all_security_groups.return_value = [ec2_group] rule = self.ec2_rule_transformer.to_rule(ec2_rule) self.assertEqual(rule.group_name, 'secGroup')
def test_should_set_group_name_from_grant(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule( ).with_allowed_security_group_id(123).build() ec2_group = Mock() ec2_group.name = 'secGroup' self.ec2_connection.get_all_security_groups.return_value = [ec2_group] rule = self.ec2_rule_transformer.to_rule(ec2_rule) self.assertEqual(rule.group_name, 'secGroup')
def test_should_return_false_if_rules_have_allowed_groups_with_different_names( self): self.openstack_rule['ip_range'] = {} self.openstack_rule['group'] = {'name': 'secGroup'} self.ec2_connection.get_all_security_groups.return_value = [ self.FakeSecurityGroup('secGroup2') ] ec2_rule = FakeEC2RuleBuilder.an_ec2_rule()\ .with_allowed_security_group_id(5)\ .build() self.assertFalse( self.rule_comparator.rules_are_equal(self.openstack_rule, ec2_rule))
def test_should_copy_to_port(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule().build() rule = self.ec2_rule_transformer.to_rule(ec2_rule) self.assertEqual(rule.to_port, ec2_rule.to_port)
def test_should_copy_ip_protocol(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule().build() rule = self.ec2_rule_transformer.to_rule(ec2_rule) self.assertEqual(rule.ip_protocol, ec2_rule.ip_protocol)
def test_should_copy_ip_range_attribute_from_grant(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule().with_ip_range('5.6.7.8/90').build() rule = self.ec2_rule_transformer.to_rule(ec2_rule) self.assertEqual(rule.ip_range, ec2_rule.grants[0].cidr_ip)
def test_should_return_false_if_rules_have_different_ip_range(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule().with_ip_range("1.1.1.1/1").build() self.assertFalse(self.rule_comparator.rules_are_equal(self.openstack_rule, ec2_rule))
def test_should_return_false_if_rules_have_different_from_ports(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule().with_from_port(2222).build() self.assertFalse(self.rule_comparator.rules_are_equal(self.openstack_rule, ec2_rule))
def test_should_return_true_if_rules_have_matching_ip_protocol_from_port_to_port_and_ip_range(self): ec2_rule = FakeEC2RuleBuilder.an_ec2_rule().build() self.assertTrue(self.rule_comparator.rules_are_equal(self.openstack_rule, ec2_rule))