def test_class_properties(self): ctx = self._get_ctx() with patch(PATCH_PREFIX + 'LambdaBase'): fun = function.LambdaFunction(ctx) fun.resource_id = 'test_function' fake_client = self.make_client_function('get_function', return_value={ 'Configuration': { 'FunctionName': 'test_function' } }) fun.client = fake_client result = fun.properties self.assertEqual(result, {'FunctionName': 'test_function'}) fake_client = self.make_client_function( 'get_function', return_value={'Configuration': None}) fun.client = fake_client result = fun.properties self.assertIsNone(result) fake_client = self.make_client_function( 'get_function', side_effect=self.get_client_error_exception('get_function')) fun.client = fake_client result = fun.properties self.assertIsNone(result)
def test_class_delete(self): ctx = self._get_ctx() with patch(PATCH_PREFIX + 'LambdaBase'): fun = function.LambdaFunction(ctx) fun.logger = MagicMock() fun.resource_id = 'test_function' fake_client = self.make_client_function('delete_function', return_value=None) fun.client = fake_client fun.delete({'param': 'params'})
def test_class_invoke(self): ctx = self._get_ctx() with patch(PATCH_PREFIX + 'LambdaBase'): fun = function.LambdaFunction(ctx) fun.logger = MagicMock() fun.resource_id = 'test_function' fake_client = self.make_client_function( 'invoke', return_value={'Payload': StringIO(u"text")}) fun.client = fake_client result = fun.invoke({'param': 'params'}) self.assertEqual(result, {'Payload': u'text'}) fake_client = self.make_client_function('invoke', return_value='') fun.client = fake_client result = fun.invoke({'param': 'params'}) self.assertEqual(result, '')
def test_class_create(self): ctx = self._get_ctx() with patch(PATCH_PREFIX + 'LambdaBase'): fun = function.LambdaFunction(ctx) fun.logger = MagicMock() fun.resource_id = 'test_function' fake_client = self.make_client_function('create_function', return_value={ 'FunctionArn': 'test_function_arn', 'FunctionName': 'test_function' }) fun.client = fake_client res_id, farn = fun.create({'param': 'params'}) self.assertEqual(res_id, fun.resource_id) self.assertEqual(farn, 'test_function_arn')
def test_create_with_download(self): subnettarget = MockRelationshipContext( target=MockCloudifyContext('subnet')) subnettarget.target.node.type_hierarchy =\ ['cloudify.nodes.aws.ec2.Subnet'] ctx = MockCloudifyContext("test_create") ctx.download_resource = MagicMock(return_value='abc') with patch(PATCH_PREFIX + 'LambdaBase'),\ patch(PATCH_PREFIX + 'utils') as utils,\ patch(PATCH_PREFIX + 'path_exists', MagicMock(return_value=False)),\ patch(PATCH_PREFIX + 'os_remove', MagicMock(return_value=True)),\ patch(PATCH_PREFIX + 'open', MagicMock(return_value=StringIO(u"test"))): fun = function.LambdaFunction(ctx) fun.logger = MagicMock() fun.resource_id = 'test_function' fake_client = self.make_client_function('create_function', return_value={ 'FunctionArn': 'test_function_arn', 'FunctionName': 'test_function' }) fun.client = fake_client resource_config = { 'VpcConfig': { 'SubnetIds': [] }, 'Code': { 'ZipFile': True } } utils.find_rels_by_node_type = MagicMock( return_value=[subnettarget]) utils.get_resource_id = MagicMock(return_value='test_id') utils.find_rel_by_node_type = MagicMock(return_value=subnettarget) utils.get_resource_id = MagicMock(return_value='Role') function.create(ctx, fun, resource_config) self.assertEqual('test', resource_config['Code']['ZipFile']) self.assertEqual( { 'SubnetIds': ['Role'], 'SecurityGroupIds': ['Role'] }, resource_config['VpcConfig'])
def test_class_status(self): ctx = self._get_ctx() with patch(PATCH_PREFIX + 'LambdaBase'): fun = function.LambdaFunction(ctx) fun.resource_id = 'test_function' fake_client = self.make_client_function('get_function', return_value={ 'Configuration': { 'FunctionName': 'test_function' } }) fun.client = fake_client status = fun.status self.assertEqual(status, 'available') fake_client = self.make_client_function('get_function', return_value={}) fun.client = fake_client status = fun.status self.assertIsNone(status)