Esempio n. 1
0
 def test_that_when_creating_a_function_fails_the_create_function_method_returns_error(
     self,
 ):
     """
     tests False function not created.
     """
     with patch.dict(
         boto_lambda.__salt__,
         {"boto_iam.get_account_id": MagicMock(return_value="1234")},
     ):
         self.conn.create_function.side_effect = ClientError(
             error_content, "create_function"
         )
         with TempZipFile() as zipfile:
             lambda_creation_result = boto_lambda.create_function(
                 FunctionName="testfunction",
                 Runtime="python2.7",
                 Role="myrole",
                 Handler="file.method",
                 ZipFile=zipfile,
                 **conn_parameters
             )
     self.assertEqual(
         lambda_creation_result.get("error", {}).get("message"),
         error_message.format("create_function"),
     )
Esempio n. 2
0
 def test_that_when_creating_a_function_with_zipfile_and_s3_raises_a_salt_invocation_error(
     self,
 ):
     """
     tests Creating a function without code
     """
     with patch.dict(
         boto_lambda.__salt__,
         {"boto_iam.get_account_id": MagicMock(return_value="1234")},
     ):
         with self.assertRaisesRegex(
             SaltInvocationError,
             "Either ZipFile must be specified, or S3Bucket and S3Key must be"
             " provided.",
         ):
             with TempZipFile() as zipfile:
                 lambda_creation_result = boto_lambda.create_function(
                     FunctionName="testfunction",
                     Runtime="python2.7",
                     Role="myrole",
                     Handler="file.method",
                     ZipFile=zipfile,
                     S3Bucket="bucket",
                     S3Key="key",
                     **conn_parameters
                 )
Esempio n. 3
0
 def test_that_when_creating_a_function_without_code_raises_a_salt_invocation_error(self):
     '''
     tests Creating a function without code
     '''
     with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}):
         with self.assertRaisesRegexp(SaltInvocationError,
                                  'Either ZipFile must be specified, or S3Bucket and S3Key must be provided.'):
             lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction',
                                                 Runtime='python2.7',
                                                 Role='myrole',
                                                 Handler='file.method',
                                                 **conn_parameters)
 def test_that_when_creating_a_function_without_code_raises_a_salt_invocation_error(self):
     '''
     tests Creating a function without code
     '''
     with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}):
         with self.assertRaisesRegexp(SaltInvocationError,
                                  'Either ZipFile must be specified, or S3Bucket and S3Key must be provided.'):
             lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction',
                                                 Runtime='python2.7',
                                                 Role='myrole',
                                                 Handler='file.method',
                                                 **conn_parameters)
 def test_that_when_creating_a_function_fails_the_create_function_method_returns_error(self):
     '''
     tests False function not created.
     '''
     with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}):
         self.conn.create_function.side_effect = ClientError(error_content, 'create_function')
         with TempZipFile() as zipfile:
             lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction',
                                                 Runtime='python2.7',
                                                 Role='myrole',
                                                 Handler='file.method',
                                                 ZipFile=zipfile,
                                                 **conn_parameters)
     self.assertEqual(lambda_creation_result.get('error', {}).get('message'), error_message.format('create_function'))
Esempio n. 6
0
 def test_that_when_creating_a_function_fails_the_create_function_method_returns_error(self):
     '''
     tests False function not created.
     '''
     with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}):
         self.conn.create_function.side_effect = ClientError(error_content, 'create_function')
         with TempZipFile() as zipfile:
             lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction',
                                                 Runtime='python2.7',
                                                 Role='myrole',
                                                 Handler='file.method',
                                                 ZipFile=zipfile,
                                                 **conn_parameters)
     self.assertEqual(lambda_creation_result.get('error', {}).get('message'), error_message.format('create_function'))
    def test_that_when_creating_a_function_from_s3_succeeds_the_create_function_method_returns_true(self):
        '''
        tests True function created.
        '''
        with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}):
            self.conn.create_function.return_value = function_ret
            lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction',
                                                    Runtime='python2.7',
                                                    Role='myrole',
                                                    Handler='file.method',
                                                    S3Bucket='bucket',
                                                    S3Key='key',
                                                    **conn_parameters)

        self.assertTrue(lambda_creation_result['created'])
Esempio n. 8
0
 def test_that_when_creating_a_function_without_code_raises_a_salt_invocation_error(self):
     """
     tests Creating a function without code
     """
     with patch.dict(boto_lambda.__salt__, {"boto_iam.get_account_id": MagicMock(return_value="1234")}):
         with self.assertRaisesRegexp(
             SaltInvocationError, "Either ZipFile must be specified, or S3Bucket and S3Key must be provided."
         ):
             lambda_creation_result = boto_lambda.create_function(
                 FunctionName="testfunction",
                 Runtime="python2.7",
                 Role="myrole",
                 Handler="file.method",
                 **conn_parameters
             )
Esempio n. 9
0
    def test_that_when_creating_a_function_from_s3_succeeds_the_create_function_method_returns_true(self):
        '''
        tests True function created.
        '''
        with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}):
            self.conn.create_function.return_value = function_ret
            lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction',
                                                    Runtime='python2.7',
                                                    Role='myrole',
                                                    Handler='file.method',
                                                    S3Bucket='bucket',
                                                    S3Key='key',
                                                    **conn_parameters)

        self.assertTrue(lambda_creation_result['created'])
Esempio n. 10
0
    def test_that_when_creating_a_function_from_s3_succeeds_the_create_function_method_returns_true(self):
        """
        tests True function created.
        """
        with patch.dict(boto_lambda.__salt__, {"boto_iam.get_account_id": MagicMock(return_value="1234")}):
            self.conn.create_function.return_value = function_ret
            lambda_creation_result = boto_lambda.create_function(
                FunctionName="testfunction",
                Runtime="python2.7",
                Role="myrole",
                Handler="file.method",
                S3Bucket="bucket",
                S3Key="key",
                **conn_parameters
            )

        self.assertTrue(lambda_creation_result["created"])
Esempio n. 11
0
 def test_that_when_creating_a_function_fails_the_create_function_method_returns_error(self):
     """
     tests False function not created.
     """
     with patch.dict(boto_lambda.__salt__, {"boto_iam.get_account_id": MagicMock(return_value="1234")}):
         self.conn.create_function.side_effect = ClientError(error_content, "create_function")
         with TempZipFile() as zipfile:
             lambda_creation_result = boto_lambda.create_function(
                 FunctionName="testfunction",
                 Runtime="python2.7",
                 Role="myrole",
                 Handler="file.method",
                 ZipFile=zipfile,
                 **conn_parameters
             )
     self.assertEqual(
         lambda_creation_result.get("error", {}).get("message"), error_message.format("create_function")
     )
Esempio n. 12
0
    def test_that_when_creating_a_function_from_s3_succeeds_the_create_function_method_returns_true(
        self, ):
        """
        tests True function created.
        """
        with patch.dict(
                boto_lambda.__salt__,
            {"boto_iam.get_account_id": MagicMock(return_value="1234")},
        ):
            self.conn.create_function.return_value = function_ret
            lambda_creation_result = boto_lambda.create_function(
                FunctionName="testfunction",
                Runtime="python2.7",
                Role="myrole",
                Handler="file.method",
                S3Bucket="bucket",
                S3Key="key",
                **conn_parameters)

        self.assertTrue(lambda_creation_result["created"])
Esempio n. 13
0
    def test_that_when_creating_a_function_from_zipfile_succeeds_the_create_function_method_returns_true(
        self,
    ):
        """
        tests True function created.
        """
        with patch.dict(
            boto_lambda.__salt__,
            {"boto_iam.get_account_id": MagicMock(return_value="1234")},
        ):
            with TempZipFile() as zipfile:
                self.conn.create_function.return_value = function_ret
                lambda_creation_result = boto_lambda.create_function(
                    FunctionName="testfunction",
                    Runtime="python2.7",
                    Role="myrole",
                    Handler="file.method",
                    ZipFile=zipfile,
                    **conn_parameters
                )

        assert lambda_creation_result["created"]