예제 #1
0
 def test_disassociate_external_resource_naively(self, *_):
     """ Tests that disassociate_external_resource_naively
         returns True when the resource is external.
     """
     ctx = self.mock_relationship_context(
             'test_disassociate_external_resource_naively')
     current_ctx.set(ctx=ctx)
     relation = AwsBaseRelationship()
     relation.source_is_external_resource = True
     self.assertEqual(True,
                      relation.disassociate_external_resource_naively())
예제 #2
0
 def test_get_related_targets_and_types(self):
     """ Tests that get_related_targets_and_types
         returns the right targets_and_types.
     """
     ctx = self.mock_relationship_context(
             'test_get_related_targets_and_types')
     current_ctx.set(ctx=ctx)
     relation = AwsBaseRelationship()
     relationships = []
     self.assertEqual({}, relation.get_related_targets_and_types(
             relationships))
예제 #3
0
 def test_get_source_resource(self, *_):
     """ Tests that get_source_resource
         gets the right resource.
     """
     ctx = self.mock_relationship_context('test_get_source_resource')
     current_ctx.set(ctx=ctx)
     relation = AwsBaseRelationship()
     ctx.source.instance.runtime_properties['aws_resource_id'] = \
         relation.source_resource_id
     resource_id = 'r-1234abcd'
     self.assertEqual(resource_id, relation.get_source_resource())
예제 #4
0
 def test_get_target_ids_of_relationship_type(self):
     """ Tests that get_target_ids_of_relationship_type
         returns the right target id.
     """
     ctx = self.mock_relationship_context(
             'test_get_target_ids_of_relationship_type')
     current_ctx.set(ctx=ctx)
     relation = AwsBaseRelationship()
     relationship_type = ctx.target.instance.runtime_properties[
         'relationships']
     with mock.patch('cloudify_aws.base.AwsBase'
                     '.get_related_targets_and_types') \
             as mock_get_related_targets_and_types:
         resource_id = 'r-1234abcd'
         mock_get_related_targets_and_types.return_value = {
             'cloudify.aws.relationships.root_connected_to_root':
                 resource_id}
         relationships = relation.get_related_targets_and_types(
                 relationship_type)
         self.assertIn(resource_id,
                       relation.get_target_ids_of_relationship_type(
                               relationship_type, relationships))
예제 #5
0
 def test_relationship_operation_functions(self):
     """ Tests that the base relationship operations
         associate, disassociate
         returns False.
     """
     ctx = self.mock_relationship_context(
             'test_relationship_operation_functions')
     current_ctx.set(ctx=ctx)
     relation = AwsBaseRelationship()
     # testing operations
     for operation in ('associate', 'disassociate'):
         function = getattr(relation, operation)
         output = function()
         self.assertEquals(False, output)
예제 #6
0
 def test_relationship_operation_handler_functions(self):
     """ Tests that the base relationship operation helpers
         associate_helper, disassociate_helper
         runs as expected.
     """
     ctx = self.mock_relationship_context(
             'test_relationship_operation_handler_functions')
     current_ctx.set(ctx=ctx)
     relation = AwsBaseRelationship()
     for operation in ('associate', 'disassociate'):
         with mock.patch('cloudify_aws.base.AwsBaseRelationship.{0}'
                         .format(operation)) as mock_operation:
             function = getattr(relation, '{0}_helper'
                                .format(operation))
             output = function()
             self.assertEqual(output, True)
             mock_operation.return_value = False
             function = getattr(relation, '{0}_helper'
                                .format(operation))
         with self.assertRaisesRegexp(
                 NonRecoverableError,
                 'Source is neither external resource, '
                 'nor Cloudify resource'):
             function()
예제 #7
0
 def test_use_source_external_resource_naively(self):
     """ Tests that use_source_external_resource_naively
         returns True when the resource is external
         or calls raise_forbidden_external_resource.
     """
     ctx = self.mock_relationship_context(
             'test_use_source_external_resource_naively')
     current_ctx.set(ctx=ctx)
     relation = AwsBaseRelationship()
     relation.source_is_external_resource = True
     with mock.patch('cloudify_aws.base.AwsBaseRelationship'
                     '.get_source_resource') as mock_get_source_resource:
         self.assertEqual(True,
                          relation.use_source_external_resource_naively())
         mock_get_source_resource._mock_return_value = None
         with self.assertRaisesRegexp(
             NonRecoverableError,
                 'is not in this account'):
             relation.use_source_external_resource_naively()