def test_aws_lambda_invoke_with_args(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    mock_payload = {"some": "response"}
    mock_response = {"Payload": MagicMock()}
    mock_response["Payload"].read.return_value = json.dumps(
        mock_payload).encode()
    client.invoke.return_value = mock_response
    lambda_function_name = "my-lambda-function"
    function_arguments = {"some": "argument"}
    invocation_type = "Event"
    client_context = {"some": "context"}
    qualifier = "$LATEST"

    invoke_function(
        function_name=lambda_function_name,
        function_arguments=function_arguments,
        invocation_type=invocation_type,
        client_context=client_context,
        qualifier=qualifier,
    )

    client.invoke.assert_called_with(
        FunctionName=lambda_function_name,
        InvocationType=invocation_type,
        LogType="None",
        Payload=json.dumps(function_arguments),
        ClientContext=b64encode(json.dumps(client_context).encode()).decode(),
        Qualifier=qualifier,
    )
Esempio n. 2
0
def test_aws_lambda_invoke_with_args(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    mock_payload = {'some': 'response'}
    mock_response = {'Payload': MagicMock()}
    mock_response['Payload'].read.return_value = json.dumps(
        mock_payload).encode()
    client.invoke.return_value = mock_response
    lambda_function_name = 'my-lambda-function'
    function_arguments = {'some': 'argument'}
    invocation_type = 'Event'
    client_context = {'some': 'context'}
    qualifier = '$LATEST'

    invoke_function(function_name=lambda_function_name,
                    function_arguments=function_arguments,
                    invocation_type=invocation_type,
                    client_context=client_context,
                    qualifier=qualifier)

    client.invoke.assert_called_with(
        FunctionName=lambda_function_name,
        InvocationType=invocation_type,
        LogType='None',
        Payload=json.dumps(function_arguments),
        ClientContext=b64encode(json.dumps(client_context).encode()).decode(),
        Qualifier=qualifier)
Esempio n. 3
0
def test_aws_lambda_invoke_failed(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    client.invoke.side_effect = Exception('Some Exception')
    lambda_function_name = 'my-lambda-function'
    with pytest.raises(FailedActivity):
        invoke_function(lambda_function_name)
    client.invoke.assert_called_with(FunctionName=lambda_function_name,
                                     InvocationType='RequestResponse',
                                     LogType='None')
Esempio n. 4
0
def test_aws_lambda_invoke_empty_response_payload(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    mock_response = {'Payload': MagicMock()}
    mock_response['Payload'].read.return_value = b''
    client.invoke.return_value = mock_response
    lambda_function_name = 'my-lambda-function'

    response = invoke_function(lambda_function_name, invocation_type='Event')

    assert response['Payload'] == ''
    client.invoke.assert_called_with(FunctionName=lambda_function_name,
                                     InvocationType='Event',
                                     LogType='None')
def test_aws_lambda_invoke_empty_response_payload(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    mock_response = {"Payload": MagicMock()}
    mock_response["Payload"].read.return_value = b""
    client.invoke.return_value = mock_response
    lambda_function_name = "my-lambda-function"

    response = invoke_function(lambda_function_name, invocation_type="Event")

    assert response["Payload"] == ""
    client.invoke.assert_called_with(FunctionName=lambda_function_name,
                                     InvocationType="Event",
                                     LogType="None")
Esempio n. 6
0
def test_aws_lambda_invoke_no_args(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    mock_payload = {'some': 'response'}
    mock_response = {'Payload': MagicMock()}
    mock_response['Payload'].read.return_value = json.dumps(
        mock_payload).encode()
    client.invoke.return_value = mock_response
    lambda_function_name = 'my-lambda-function'

    response = invoke_function(lambda_function_name)

    assert response['Payload'] == mock_payload
    client.invoke.assert_called_with(FunctionName=lambda_function_name,
                                     InvocationType='RequestResponse',
                                     LogType='None')
def test_aws_lambda_invoke_no_args(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    mock_payload = {"some": "response"}
    mock_response = {"Payload": MagicMock()}
    mock_response["Payload"].read.return_value = json.dumps(
        mock_payload).encode()
    client.invoke.return_value = mock_response
    lambda_function_name = "my-lambda-function"

    response = invoke_function(lambda_function_name)

    assert response["Payload"] == mock_payload
    client.invoke.assert_called_with(
        FunctionName=lambda_function_name,
        InvocationType="RequestResponse",
        LogType="None",
    )