Example #1
0
def test_send_called_with_success(echo_event, context):
    """It should call send if there is a response url in the event on success."""
    event = echo_event

    with patch("cf.cfnresponse.send") as mock_send:
        handler(event, context)

    mock_send.assert_called_once_with(event, context, cfnresponse.SUCCESS, ANY)
Example #2
0
def test_send_called_with_failed(echo_event, context):
    """It should call send if there is a response url in the event on failure."""
    event = echo_event
    event["ResourceProperties"] = {"Operator": "unknown", "Operands": "test"}

    with patch("cf.cfnresponse.send") as mock_send:
        handler(event, context)

    mock_send.assert_called_once_with(event, context, cfnresponse.FAILED, ANY)
Example #3
0
def test_send_not_called(echo_event, context):
    """It should not call send if there is no response url in the event."""
    event = echo_event

    if "ResponseURL" in event:
        del event["ResponseURL"]

    with patch("cf.cfnresponse.send") as mock_send:
        handler(event, context)

    mock_send.assert_not_called()
def test_handler_400(operator, operands):
    event = {
        "ResourceProperties": {
            "Operator": operator,
            "Operands": operands
        }
    }
    response = handler(event, {})
    body = json.loads(response["body"])

    assert int(response["statusCode"]) == 400
    assert body["Exception"]
def test_handler_200(operator, operands):
    event = {
        "ResourceProperties": {
            "Operator": operator,
            "Operands": operands
        }
    }
    response = handler(event, {})
    body = json.loads(response["body"])

    if not isinstance(operands, (list)):
        operands = [operands]

    assert body["Value"] == operands
    assert int(response["statusCode"]) == 200