Ejemplo n.º 1
0
 def test_create_function_is_retried_and_succeeds(self, stubbed_session):
     kwargs = {
         'FunctionName': 'name',
         'Runtime': 'python2.7',
         'Code': {'ZipFile': b'foo'},
         'Handler': 'app.app',
         'Role': 'myarn',
     }
     stubbed_session.stub('lambda').create_function(
         **kwargs).raises_error(
         error_code='InvalidParameterValueException',
         message=('The role defined for the function cannot '
                  'be assumed by Lambda.'))
     stubbed_session.stub('lambda').create_function(
         **kwargs).raises_error(
         error_code='InvalidParameterValueException',
         message=('The role defined for the function cannot '
                  'be assumed by Lambda.'))
     stubbed_session.stub('lambda').create_function(
         **kwargs).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
     assert awsclient.create_function(
         'name', 'myarn', b'foo',
         'python2.7', 'app.app') == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 2
0
 def test_create_function_is_retried_and_succeeds(self, stubbed_session):
     kwargs = {
         'FunctionName': 'name',
         'Runtime': 'python2.7',
         'Code': {'ZipFile': b'foo'},
         'Handler': 'app.app',
         'Role': 'myarn',
     }
     stubbed_session.stub('lambda').create_function(
         **kwargs).raises_error(
         error_code='InvalidParameterValueException',
         message=('The role defined for the function cannot '
                  'be assumed by Lambda.'))
     stubbed_session.stub('lambda').create_function(
         **kwargs).raises_error(
         error_code='InvalidParameterValueException',
         message=('The role defined for the function cannot '
                  'be assumed by Lambda.'))
     stubbed_session.stub('lambda').create_function(
         **kwargs).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
     assert awsclient.create_function(
         'name', 'myarn', b'foo', 'python2.7', 'app.app') == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 3
0
 def test_create_function_propagates_unknown_error(self, stubbed_session):
     kwargs = {
         'FunctionName': 'name',
         'Runtime': 'python2.7',
         'Code': {'ZipFile': b'foo'},
         'Handler': 'app.app',
         'Role': 'myarn',
     }
     stubbed_session.stub('lambda').create_function(
         **kwargs).raises_error(
         error_code='UnknownException', message='')
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
     with pytest.raises(botocore.exceptions.ClientError):
         awsclient.create_function('name', 'myarn', b'foo', 'pytohn2.7')
     stubbed_session.verify_stubs()
Ejemplo n.º 4
0
 def test_create_function_propagates_unknown_error(self, stubbed_session):
     kwargs = {
         'FunctionName': 'name',
         'Runtime': 'python2.7',
         'Code': {'ZipFile': b'foo'},
         'Handler': 'app.app',
         'Role': 'myarn',
         'Timeout': 60,
     }
     stubbed_session.stub('lambda').create_function(
         **kwargs).raises_error(
         error_code='UnknownException', message='')
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
     with pytest.raises(botocore.exceptions.ClientError):
         awsclient.create_function('name', 'myarn', b'foo')
     stubbed_session.verify_stubs()
Ejemplo n.º 5
0
    def test_create_function_fails_after_max_retries(self, stubbed_session):
        kwargs = {
            'FunctionName': 'name',
            'Runtime': 'python2.7',
            'Code': {'ZipFile': b'foo'},
            'Handler': 'app.app',
            'Role': 'myarn',
        }
        for _ in range(TypedAWSClient.LAMBDA_CREATE_ATTEMPTS):
            stubbed_session.stub('lambda').create_function(
                **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.create_function('name', 'myarn', b'foo', 'python2.7')
        stubbed_session.verify_stubs()
Ejemplo n.º 6
0
 def test_raises_large_deployment_error_for_too_large_unzip(
         self, stubbed_session):
     kwargs = {
         'FunctionName': 'name',
         'Runtime': 'python2.7',
         'Code': {'ZipFile': b'foo'},
         'Handler': 'app.app',
         'Role': 'myarn',
     }
     stubbed_session.stub('lambda').create_function(
         **kwargs).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.create_function('name', 'myarn', b'foo', 'python2.7',
                                   'app.app')
     stubbed_session.verify_stubs()
Ejemplo n.º 7
0
 def test_raises_large_deployment_error_request_entity_to_large(
         self, stubbed_session):
     kwargs = {
         'FunctionName': 'name',
         'Runtime': 'python2.7',
         'Code': {'ZipFile': b'foo'},
         'Handler': 'app.app',
         'Role': 'myarn',
     }
     stubbed_session.stub('lambda').create_function(
         **kwargs).raises_error(
             error_code='RequestEntityTooLargeException',
             message='')
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
     with pytest.raises(DeploymentPackageTooLargeError):
         awsclient.create_function('name', 'myarn', b'foo', 'python2.7',
                                   'app.app')
     stubbed_session.verify_stubs()
Ejemplo n.º 8
0
 def test_raises_large_deployment_error_request_entity_to_large(
         self, stubbed_session):
     kwargs = {
         'FunctionName': 'name',
         'Runtime': 'python2.7',
         'Code': {'ZipFile': b'foo'},
         'Handler': 'app.app',
         'Role': 'myarn',
     }
     stubbed_session.stub('lambda').create_function(
         **kwargs).raises_error(
             error_code='RequestEntityTooLargeException',
             message='')
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
     with pytest.raises(DeploymentPackageTooLargeError):
         awsclient.create_function('name', 'myarn', b'foo', 'python2.7',
                                   'app.app')
     stubbed_session.verify_stubs()
Ejemplo n.º 9
0
    def test_create_function_fails_after_max_retries(self, stubbed_session):
        kwargs = {
            'FunctionName': 'name',
            'Runtime': 'python2.7',
            'Code': {'ZipFile': b'foo'},
            'Handler': 'app.app',
            'Role': 'myarn',
            'Timeout': 60,
        }
        for _ in range(TypedAWSClient.LAMBDA_CREATE_ATTEMPTS):
            stubbed_session.stub('lambda').create_function(
                **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.create_function('name', 'myarn', b'foo')
        stubbed_session.verify_stubs()
Ejemplo n.º 10
0
 def test_raises_large_deployment_error_for_too_large_unzip(
         self, stubbed_session):
     kwargs = {
         'FunctionName': 'name',
         'Runtime': 'python2.7',
         'Code': {'ZipFile': b'foo'},
         'Handler': 'app.app',
         'Role': 'myarn',
     }
     stubbed_session.stub('lambda').create_function(
         **kwargs).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.create_function('name', 'myarn', b'foo', 'python2.7',
                                   'app.app')
     stubbed_session.verify_stubs()
Ejemplo n.º 11
0
    def test_no_raise_large_deployment_error_when_small_deployment_size(
            self, stubbed_session):
        kwargs = {
            'FunctionName': 'name',
            'Runtime': 'python2.7',
            'Code': {'ZipFile': b'foo'},
            'Handler': 'app.app',
            'Role': 'myarn',
        }

        stubbed_session.stub('lambda').create_function(
            **kwargs).raises_error(error=RequestsConnectionError())
        stubbed_session.activate_stubs()
        awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
        with pytest.raises(LambdaClientError) as excinfo:
            awsclient.create_function('name', 'myarn', b'foo',
                                      'python2.7', 'app.app')
        stubbed_session.verify_stubs()
        assert not isinstance(excinfo.value, DeploymentPackageTooLargeError)
        assert isinstance(
            excinfo.value.original_error, RequestsConnectionError)
Ejemplo n.º 12
0
    def test_no_raise_large_deployment_error_when_small_deployment_size(
            self, stubbed_session):
        kwargs = {
            'FunctionName': 'name',
            'Runtime': 'python2.7',
            'Code': {'ZipFile': b'foo'},
            'Handler': 'app.app',
            'Role': 'myarn',
        }

        stubbed_session.stub('lambda').create_function(
            **kwargs).raises_error(error=RequestsConnectionError())
        stubbed_session.activate_stubs()
        awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
        with pytest.raises(LambdaClientError) as excinfo:
            awsclient.create_function('name', 'myarn', b'foo',
                                      'python2.7', 'app.app')
        stubbed_session.verify_stubs()
        assert not isinstance(excinfo.value, DeploymentPackageTooLargeError)
        assert isinstance(
            excinfo.value.original_error, RequestsConnectionError)
Ejemplo n.º 13
0
    def test_raises_large_deployment_error_for_connection_error(
            self, stubbed_session):
        too_large_content = b'a' * 60 * (1024 ** 2)
        kwargs = {
            'FunctionName': 'name',
            'Runtime': 'python2.7',
            'Code': {'ZipFile': too_large_content},
            'Handler': 'app.app',
            'Role': 'myarn',
        }

        stubbed_session.stub('lambda').create_function(
            **kwargs).raises_error(error=RequestsConnectionError())
        stubbed_session.activate_stubs()
        awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
        with pytest.raises(DeploymentPackageTooLargeError) as excinfo:
            awsclient.create_function('name', 'myarn', too_large_content,
                                      'python2.7', 'app.app')
        stubbed_session.verify_stubs()
        assert excinfo.value.context.function_name ==  'name'
        assert excinfo.value.context.client_method_name == 'create_function'
        assert excinfo.value.context.deployment_size ==  60 * (1024 ** 2)
Ejemplo n.º 14
0
 def test_can_pass_python_runtime(self, stubbed_session):
     stubbed_session.stub('lambda').create_function(
         FunctionName='name',
         Runtime='python3.6',
         Code={'ZipFile': b'foo'},
         Handler='app.app',
         Role='myarn',
     ).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.create_function(
         'name', 'myarn', b'foo', runtime='python3.6') == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 15
0
    def test_raises_large_deployment_error_for_connection_error(
            self, stubbed_session):
        too_large_content = b'a' * 60 * (1024 ** 2)
        kwargs = {
            'FunctionName': 'name',
            'Runtime': 'python2.7',
            'Code': {'ZipFile': too_large_content},
            'Handler': 'app.app',
            'Role': 'myarn',
        }

        stubbed_session.stub('lambda').create_function(
            **kwargs).raises_error(error=RequestsConnectionError())
        stubbed_session.activate_stubs()
        awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
        with pytest.raises(DeploymentPackageTooLargeError) as excinfo:
            awsclient.create_function('name', 'myarn', too_large_content,
                                      'python2.7', 'app.app')
        stubbed_session.verify_stubs()
        assert excinfo.value.context.function_name == 'name'
        assert excinfo.value.context.client_method_name == 'create_function'
        assert excinfo.value.context.deployment_size == 60 * (1024 ** 2)
Ejemplo n.º 16
0
 def test_create_function_succeeds_first_try(self, stubbed_session):
     stubbed_session.stub('lambda').create_function(
         FunctionName='name',
         Runtime='python2.7',
         Code={'ZipFile': b'foo'},
         Handler='app.app',
         Role='myarn',
         Timeout=60,
     ).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.create_function(
         'name', 'myarn', b'foo') == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 17
0
 def test_create_function_succeeds_first_try(self, stubbed_session):
     stubbed_session.stub('lambda').create_function(
         FunctionName='name',
         Runtime='python2.7',
         Code={'ZipFile': b'foo'},
         Handler='app.app',
         Role='myarn',
         Timeout=60,
     ).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.create_function(
         'name', 'myarn', b'foo') == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 18
0
 def test_can_pass_python_runtime(self, stubbed_session):
     stubbed_session.stub('lambda').create_function(
         FunctionName='name',
         Runtime='python3.6',
         Code={'ZipFile': b'foo'},
         Handler='app.app',
         Role='myarn',
     ).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.create_function(
         'name', 'myarn', b'foo',
         runtime='python3.6', handler='app.app') == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 19
0
    def test_create_function_fails_after_max_retries(self, stubbed_session):
        kwargs = {
            'FunctionName': 'name',
            'Runtime': 'python2.7',
            'Code': {'ZipFile': b'foo'},
            'Handler': 'app.app',
            'Role': 'myarn',
        }
        for _ in range(TypedAWSClient.LAMBDA_CREATE_ATTEMPTS):
            stubbed_session.stub('lambda').create_function(
                **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(LambdaClientError) as excinfo:
            awsclient.create_function('name', 'myarn', b'foo', 'python2.7',
                                      'app.app')
        assert isinstance(
            excinfo.value.original_error, botocore.exceptions.ClientError)
        stubbed_session.verify_stubs()
Ejemplo n.º 20
0
 def test_create_function_with_environment_variables(self, stubbed_session):
     stubbed_session.stub('lambda').create_function(
         FunctionName='name',
         Runtime='python2.7',
         Code={'ZipFile': b'foo'},
         Handler='app.app',
         Role='myarn',
         Environment={'Variables': {'FOO': 'BAR'}}
     ).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.create_function(
         'name', 'myarn', b'foo', 'python2.7',
         environment_variables={'FOO': 'BAR'}) == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 21
0
    def test_create_function_fails_after_max_retries(self, stubbed_session):
        kwargs = {
            'FunctionName': 'name',
            'Runtime': 'python2.7',
            'Code': {'ZipFile': b'foo'},
            'Handler': 'app.app',
            'Role': 'myarn',
        }
        for _ in range(TypedAWSClient.LAMBDA_CREATE_ATTEMPTS):
            stubbed_session.stub('lambda').create_function(
                **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(LambdaClientError) as excinfo:
            awsclient.create_function('name', 'myarn', b'foo', 'python2.7',
                                      'app.app')
        assert isinstance(
            excinfo.value.original_error, botocore.exceptions.ClientError)
        stubbed_session.verify_stubs()
Ejemplo n.º 22
0
 def test_create_function_with_memory_size(self, stubbed_session):
     stubbed_session.stub('lambda').create_function(
         FunctionName='name',
         Runtime='python2.7',
         Code={'ZipFile': b'foo'},
         Handler='app.app',
         Role='myarn',
         MemorySize=256
     ).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.create_function(
         'name', 'myarn', b'foo', 'python2.7',
         memory_size=256) == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 23
0
 def test_create_function_with_memory_size(self, stubbed_session):
     stubbed_session.stub('lambda').create_function(
         FunctionName='name',
         Runtime='python2.7',
         Code={'ZipFile': b'foo'},
         Handler='app.app',
         Role='myarn',
         MemorySize=256
     ).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.create_function(
         'name', 'myarn', b'foo', 'python2.7', 'app.app',
         memory_size=256) == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 24
0
 def test_create_function_with_environment_variables(self, stubbed_session):
     stubbed_session.stub('lambda').create_function(
         FunctionName='name',
         Runtime='python2.7',
         Code={'ZipFile': b'foo'},
         Handler='app.app',
         Role='myarn',
         Environment={'Variables': {'FOO': 'BAR'}}
     ).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.create_function(
         'name', 'myarn', b'foo', 'python2.7',
         handler='app.app',
         environment_variables={'FOO': 'BAR'}) == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 25
0
 def test_can_provide_tags(self, stubbed_session):
     stubbed_session.stub('lambda').create_function(
         FunctionName='name',
         Runtime='python2.7',
         Code={'ZipFile': b'foo'},
         Handler='app.app',
         Role='myarn',
         Tags={'key': 'value'},
     ).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.create_function(
         function_name='name',
         role_arn='myarn',
         zip_contents=b'foo',
         runtime='python2.7',
         tags={'key': 'value'}) == 'arn:12345:name'
     stubbed_session.verify_stubs()
Ejemplo n.º 26
0
 def test_can_provide_tags(self, stubbed_session):
     stubbed_session.stub('lambda').create_function(
         FunctionName='name',
         Runtime='python2.7',
         Code={'ZipFile': b'foo'},
         Handler='app.app',
         Role='myarn',
         Tags={'key': 'value'},
     ).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.create_function(
         function_name='name',
         role_arn='myarn',
         zip_contents=b'foo',
         runtime='python2.7',
         tags={'key': 'value'},
         handler='app.app') == 'arn:12345:name'
     stubbed_session.verify_stubs()