def test_simplifies_error_msg_for_broken_pipe(self): lambda_error = DeploymentPackageTooLargeError( RequestsConnectionError( Exception('Connection aborted.', socket.error(32, 'Broken pipe'))), context=LambdaErrorContext(function_name='foo', client_method_name='create_function', deployment_size=1024**2)) deploy_error = ChaliceDeploymentError(lambda_error) deploy_error_msg = str(deploy_error) assert ('Connection aborted. Lambda closed the connection' in deploy_error_msg)
def test_simplifies_error_msg_for_timeout(self): lambda_error = DeploymentPackageTooLargeError( RequestsConnectionError( Exception('Connection aborted.', socket.timeout('The write operation timed out'))), context=LambdaErrorContext(function_name='foo', client_method_name='create_function', deployment_size=1024**2)) deploy_error = ChaliceDeploymentError(lambda_error) deploy_error_msg = str(deploy_error) assert ('Connection aborted. Timed out sending your app to Lambda.' in deploy_error_msg)
def test_error_msg_for_general_connection(self): lambda_error = DeploymentPackageTooLargeError( RequestsConnectionError( Exception('Connection aborted.', socket.error('Some vague reason'))), context=LambdaErrorContext(function_name='foo', client_method_name='create_function', deployment_size=1024**2)) deploy_error = ChaliceDeploymentError(lambda_error) deploy_error_msg = str(deploy_error) assert 'Connection aborted.' in deploy_error_msg assert 'Some vague reason' not in deploy_error_msg
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)
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)
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)
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)