def test__parse_request_fail_without_platform_creds():
    resource = Resource(TYPE_NAME, Mock())

    payload = ENTRYPOINT_PAYLOAD.copy()
    payload["requestData"] = payload["requestData"].copy()
    payload["requestData"]["platformCredentials"] = None

    with pytest.raises(InvalidRequest) as excinfo:
        resource._parse_request(payload)

    assert "ValueError" in str(excinfo.value)
Ejemplo n.º 2
0
def test__parse_request_valid_request_and__cast_resource_request():
    mock_model = Mock(spec_set=["_deserialize"])
    mock_model._deserialize.side_effect = [
        sentinel.state_out1, sentinel.state_out2
    ]

    mock_type_configuration_model = Mock(spec_set=["_deserialize"])
    mock_type_configuration_model._deserialize.side_effect = [
        sentinel.type_configuration
    ]

    resource = Resource(TYPE_NAME, mock_model, mock_type_configuration_model)

    with patch("cloudformation_cli_python_lib.resource._get_boto_session"
               ) as mock_session:
        ret = resource._parse_request(ENTRYPOINT_PAYLOAD)
    sessions, action, callback_context, request = ret

    mock_session.assert_has_calls(
        [
            call(
                Credentials(
                    **ENTRYPOINT_PAYLOAD["requestData"]["callerCredentials"])),
            call(
                Credentials(**ENTRYPOINT_PAYLOAD["requestData"]
                            ["providerCredentials"])),
        ],
        any_order=True,
    )

    # credentials are used when rescheduling, so can't zero them out (for now)
    assert request.requestData.callerCredentials is not None
    assert request.requestData.providerCredentials is not None
    assert request.requestData.typeConfiguration is sentinel.type_configuration

    caller_sess, provider_sess = sessions
    assert caller_sess is mock_session.return_value
    assert provider_sess is mock_session.return_value

    assert action == Action.CREATE
    assert callback_context == {}

    modeled_request = resource._cast_resource_request(request)

    mock_model._deserialize.assert_has_calls(
        [call(sentinel.state_in1),
         call(sentinel.state_in2)])
    assert modeled_request.clientRequestToken == request.bearerToken
    assert modeled_request.desiredResourceState is sentinel.state_out1
    assert modeled_request.previousResourceState is sentinel.state_out2
    assert modeled_request.typeConfiguration is sentinel.type_configuration
    assert modeled_request.logicalResourceIdentifier == "myBucket"
    assert modeled_request.nextToken is None