コード例 #1
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
    def test_update_function_is_retried_and_succeeds(self, stubbed_session):
        stubbed_session.stub('lambda').update_function_code(
            FunctionName='name', ZipFile=b'foo').returns(
                {'FunctionArn': 'arn'})

        update_config_kwargs = {
            'FunctionName': 'name',
            'Role': 'role-arn'
        }
        # This should fail two times with retryable exceptions and
        # then succeed to update the lambda function.
        stubbed_session.stub('lambda').update_function_configuration(
            **update_config_kwargs).raises_error(
                error_code='InvalidParameterValueException',
                message=('The role defined for the function cannot '
                         'be assumed by Lambda.'))
        stubbed_session.stub('lambda').update_function_configuration(
            **update_config_kwargs).raises_error(
            error_code='InvalidParameterValueException',
            message=('The role defined for the function cannot '
                     'be assumed by Lambda.'))
        stubbed_session.stub('lambda').update_function_configuration(
            **update_config_kwargs).returns({})
        stubbed_session.activate_stubs()
        awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
        awsclient.update_function('name', b'foo', role_arn='role-arn')
        stubbed_session.verify_stubs()
コード例 #2
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
 def test_always_update_function_code(self, stubbed_session):
     lambda_client = stubbed_session.stub('lambda')
     lambda_client.update_function_code(
         FunctionName='name', ZipFile=b'foo').returns({})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     awsclient.update_function('name', b'foo')
     stubbed_session.verify_stubs()
コード例 #3
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
 def test_raises_large_deployment_error_for_too_large_unzip(
         self, stubbed_session):
     stubbed_session.stub('lambda').update_function_code(
         FunctionName='name', ZipFile=b'foo').raises_error(
             error_code='InvalidParameterValueException',
             message='Unzipped size must be smaller than ...')
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
     with pytest.raises(DeploymentPackageTooLargeError):
         awsclient.update_function('name', b'foo')
     stubbed_session.verify_stubs()
コード例 #4
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
 def test_raises_large_deployment_error_request_entity_to_large(
         self, stubbed_session):
     stubbed_session.stub('lambda').update_function_code(
         FunctionName='name', ZipFile=b'foo').raises_error(
             error_code='RequestEntityTooLargeException',
             message='')
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
     with pytest.raises(DeploymentPackageTooLargeError):
         awsclient.update_function('name', b'foo')
     stubbed_session.verify_stubs()
コード例 #5
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
 def test_update_function_code_with_memory(self, stubbed_session):
     lambda_client = stubbed_session.stub('lambda')
     lambda_client.update_function_code(
         FunctionName='name', ZipFile=b'foo').returns({})
     lambda_client.update_function_configuration(
         FunctionName='name',
         MemorySize=256).returns({})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     awsclient.update_function('name', b'foo', memory_size=256)
     stubbed_session.verify_stubs()
コード例 #6
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
 def test_update_function_code_with_timeout(self, stubbed_session):
     lambda_client = stubbed_session.stub('lambda')
     lambda_client.update_function_code(
         FunctionName='name', ZipFile=b'foo').returns({})
     lambda_client.update_function_configuration(
         FunctionName='name',
         Timeout=240).returns({})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     awsclient.update_function('name', b'foo', timeout=240)
     stubbed_session.verify_stubs()
コード例 #7
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
 def test_update_function_code_with_environment_vars(self, stubbed_session):
     lambda_client = stubbed_session.stub('lambda')
     lambda_client.update_function_code(
         FunctionName='name', ZipFile=b'foo').returns({})
     lambda_client.update_function_configuration(
         FunctionName='name',
         Environment={'Variables': {"FOO": "BAR"}}).returns({})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     awsclient.update_function(
         'name', b'foo', {"FOO": "BAR"})
     stubbed_session.verify_stubs()
コード例 #8
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
    def test_no_raise_large_deployment_error_when_small_deployment_size(
            self, stubbed_session):
        stubbed_session.stub('lambda').update_function_code(
            FunctionName='name', ZipFile=b'foo').raises_error(
                error=RequestsConnectionError())

        stubbed_session.activate_stubs()
        awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
        with pytest.raises(LambdaClientError) as excinfo:
            awsclient.update_function('name', b'foo')
        stubbed_session.verify_stubs()
        assert not isinstance(excinfo.value, DeploymentPackageTooLargeError)
        assert isinstance(
            excinfo.value.original_error, RequestsConnectionError)
コード例 #9
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
    def test_update_function_with_no_tag_updates_needed(self, stubbed_session):
        function_arn = 'arn'

        lambda_client = stubbed_session.stub('lambda')
        lambda_client.update_function_code(
            FunctionName='name', ZipFile=b'foo').returns(
                {'FunctionArn': function_arn})
        lambda_client.list_tags(
            Resource=function_arn).returns({'Tags': {'MyKey': 'SameValue'}})
        stubbed_session.activate_stubs()

        awsclient = TypedAWSClient(stubbed_session)
        awsclient.update_function('name', b'foo', tags={'MyKey': 'SameValue'})
        stubbed_session.verify_stubs()
コード例 #10
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
    def test_update_function_with_iam_role(self, stubbed_session):
        function_arn = 'arn'

        lambda_client = stubbed_session.stub('lambda')
        lambda_client.update_function_code(
            FunctionName='name', ZipFile=b'foo').returns(
                {'FunctionArn': function_arn})
        lambda_client.update_function_configuration(
            FunctionName='name',
            Role='role-arn').returns({})
        stubbed_session.activate_stubs()

        awsclient = TypedAWSClient(stubbed_session)
        awsclient.update_function('name', b'foo', role_arn='role-arn')
        stubbed_session.verify_stubs()
コード例 #11
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
    def test_raises_large_deployment_error_for_connection_error(
            self, stubbed_session):
        too_large_content = b'a' * 60 * (1024 ** 2)
        stubbed_session.stub('lambda').update_function_code(
            FunctionName='name', ZipFile=too_large_content).raises_error(
                error=RequestsConnectionError())

        stubbed_session.activate_stubs()
        awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
        with pytest.raises(DeploymentPackageTooLargeError) as excinfo:
            awsclient.update_function('name', too_large_content)
        stubbed_session.verify_stubs()
        assert excinfo.value.context.function_name == 'name'
        assert (
            excinfo.value.context.client_method_name == 'update_function_code')
        assert excinfo.value.context.deployment_size == 60 * (1024 ** 2)
コード例 #12
0
ファイル: test_awsclient.py プロジェクト: josie00/nms
    def test_update_function_with_adding_tags(self, stubbed_session):
        function_arn = 'arn'

        lambda_client = stubbed_session.stub('lambda')
        lambda_client.update_function_code(
            FunctionName='name', ZipFile=b'foo').returns(
                {'FunctionArn': function_arn})
        lambda_client.list_tags(
            Resource=function_arn).returns({'Tags': {}})
        lambda_client.tag_resource(
            Resource=function_arn, Tags={'MyKey': 'MyValue'}).returns({})
        stubbed_session.activate_stubs()

        awsclient = TypedAWSClient(stubbed_session)
        awsclient.update_function('name', b'foo', tags={'MyKey': 'MyValue'})
        stubbed_session.verify_stubs()
コード例 #13
0
ファイル: test_awsclient.py プロジェクト: jamesls/chalice
    def test_update_function_with_removing_tags(self, stubbed_session):
        function_arn = 'arn'

        lambda_client = stubbed_session.stub('lambda')
        lambda_client.update_function_code(
            FunctionName='name', ZipFile=b'foo').returns(
                {'FunctionArn': function_arn})
        lambda_client.list_tags(
            Resource=function_arn).returns(
                {'Tags': {'KeyToRemove': 'Value'}})
        lambda_client.untag_resource(
            Resource=function_arn, TagKeys=['KeyToRemove']).returns({})
        stubbed_session.activate_stubs()

        awsclient = TypedAWSClient(stubbed_session)
        awsclient.update_function('name', b'foo', tags={})
        stubbed_session.verify_stubs()
コード例 #14
0
    def test_update_function_fails_after_max_retries(self, stubbed_session):
        stubbed_session.stub('lambda').update_function_code(
            FunctionName='name', ZipFile=b'foo').returns(
                {'FunctionArn': 'arn'})

        update_config_kwargs = {
            'FunctionName': 'name',
            'Role': 'role-arn'
        }
        for _ in range(TypedAWSClient.LAMBDA_CREATE_ATTEMPTS):
            stubbed_session.stub('lambda').update_function_configuration(
                **update_config_kwargs).raises_error(
                    error_code='InvalidParameterValueException', message='')
        stubbed_session.activate_stubs()
        awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))

        with pytest.raises(botocore.exceptions.ClientError):
            awsclient.update_function('name', b'foo', role_arn='role-arn')
        stubbed_session.verify_stubs()
コード例 #15
0
    def test_update_function_fails_after_max_retries(self, stubbed_session):
        stubbed_session.stub('lambda').update_function_code(
            FunctionName='name', ZipFile=b'foo').returns(
                {'FunctionArn': 'arn'})

        update_config_kwargs = {
            'FunctionName': 'name',
            'Role': 'role-arn'
        }
        for _ in range(TypedAWSClient.LAMBDA_CREATE_ATTEMPTS):
            stubbed_session.stub('lambda').update_function_configuration(
                **update_config_kwargs).raises_error(
                    error_code='InvalidParameterValueException',
                    message=('The role defined for the function cannot '
                             'be assumed by Lambda.'))
        stubbed_session.activate_stubs()
        awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))

        with pytest.raises(botocore.exceptions.ClientError):
            awsclient.update_function('name', b'foo', role_arn='role-arn')
        stubbed_session.verify_stubs()