Exemple #1
0
def input_typename():
    type_name = input_with_validation(
        "What's the name of your resource type?",
        validate_type_name,
        "\n(Organization::Service::Resource)",
    )
    LOG.debug("Resource type identifier: %s", type_name)
    return type_name
def input_typename():
    type_name = input_with_validation(
        "What's the name of your module type?",
        validate_type_name,
        "\n(<Organization>::<Service>::<Name>::MODULE)",
    )
    LOG.debug("Resource type identifier: %s", type_name)
    return type_name
    def _prompt_for_codegen_model(project):
        prompt = "Choose codegen model - 1 (default) or 2 (guided-aws): "

        codegen_model = input_with_validation(
            prompt, validate_codegen_model(CODEGEN.default_code))

        project.settings["codegen_template_path"] = CODEGEN.default

        if codegen_model == CODEGEN.guided_code:
            project.settings["codegen_template_path"] = CODEGEN.guided
Exemple #4
0
def input_language():
    # language/plugin
    if validate_plugin_choice.max < 1:
        LOG.critical("No language plugins found")
        raise WizardAbortError()

    if validate_plugin_choice.max == 1:
        language = validate_plugin_choice.choices[0]
        LOG.warning("One language plugin found, defaulting to %s", language)
    else:
        language = input_with_validation(validate_plugin_choice.message,
                                         validate_plugin_choice)
    LOG.debug("Language plugin: %s", language)
    return language
    def _prompt_for_namespace(self, project):
        if project.type_info[0] == "AWS":
            namespace = ("software", "amazon") + project.type_info[1:]
        else:
            namespace = ("com", ) + project.type_info

        namespace = tuple(safe_reserved(s.lower()) for s in namespace)

        prompt = "Enter a package name (empty for default '{}'): ".format(
            ".".join(namespace))

        self.namespace = input_with_validation(prompt,
                                               validate_namespace(namespace))
        project.settings["namespace"] = self.namespace
        self.package_name = ".".join(self.namespace)
def test_input_with_validation_valid_first_try(capsys):
    sentinel1 = object()
    sentinel2 = object()

    validator = Mock(return_value=sentinel1)
    with patch("rpdk.core.utils.init_utils.input",
               return_value=sentinel2) as mock_input:
        ret = input_with_validation(PROMPT, validator)

    mock_input.assert_called_once_with()
    validator.assert_called_once_with(sentinel2)
    assert ret is sentinel1

    out, err = capsys.readouterr()
    assert not err
    assert PROMPT in out
def test_input_with_validation_valid_second_try(capsys):
    def mock_validator(value):
        if value == ERROR:
            raise WizardValidationError(ERROR)
        return value

    sentinel = object()

    with patch("rpdk.core.utils.init_utils.input",
               side_effect=(ERROR, sentinel)) as mock_input:
        ret = input_with_validation(PROMPT, mock_validator)

    assert mock_input.call_count == 2
    assert ret is sentinel

    out, err = capsys.readouterr()
    assert not err
    assert ERROR in out