def test_create_lambda_function_failure(make_stubber, make_unique_name): lambda_stubber = make_stubber(batch_versioning.aws_lambda) function_name = make_unique_name('function') function_arn = f'aws:arn:EXAMPLE:{function_name}' mock_role = MagicMock() mock_role.arn = 'aws:arn:EXAMPLE:iam_role' handler = 'test_batch_versioning.test_function' lambda_stubber.stub_create_function(function_name, function_arn, mock_role.arn, handler, error_code='TestException') with pytest.raises(ClientError) as exc_info: batch_versioning.create_lambda_function(mock_role, function_name, __file__, handler, 'test lambda function') assert exc_info.value.response['Error']['Code'] == 'TestException'
def test_create_lambda_function(make_stubber, make_unique_name): lambda_stubber = make_stubber(batch_versioning.aws_lambda) function_name = make_unique_name('function') function_arn = f'aws:arn:EXAMPLE:{function_name}' mock_role = MagicMock() mock_role.arn = 'aws:arn:EXAMPLE:iam_role' handler = 'test_batch_versioning.test_function' lambda_stubber.stub_create_function(function_name, function_arn, mock_role.arn, handler) returned_arn = batch_versioning.create_lambda_function( mock_role, function_name, __file__, handler, 'test lambda function') assert returned_arn == function_arn
def test_create_lambda_function_bad_file(): with pytest.raises(IOError): batch_versioning.create_lambda_function('role', 'func', 'not_a_file.py', 'nonexistent.no_handler', 'None at all')