Exemple #1
0
def test_param_to_cfn(mocker, section_definition, param_key, param_value, expected_cfn_params):
    pcluster_config = get_mocked_pcluster_config(mocker)

    param_definition, param_type = get_param_definition(section_definition, param_key)
    param = param_type(section_definition.get("key"), "default", param_key, param_definition, pcluster_config)
    param.value = param_value
    cfn_params = param.to_cfn()
    assert_that(cfn_params).is_equal_to(expected_cfn_params)
Exemple #2
0
def test_param_from_cfn_value(mocker, section_definition, param_key, cfn_value,
                              expected_value):
    """Test conversion from cfn value of simple parameters, that don't depends from multiple CFN parameters."""
    param_definition, param_type = get_param_definition(
        section_definition, param_key)

    pcluster_config = get_mocked_pcluster_config(mocker)

    param_value = param_type(section_definition.get("key"), "default",
                             param_key, param_definition,
                             pcluster_config).get_value_from_string(cfn_value)
    assert_that(param_value).is_equal_to(expected_value)
def test_param_to_file(mocker, section_definition, param_key, param_value, expected_value):
    section_label = "default"
    section_name = section_definition.get("key") + " " + section_label
    config_parser = configparser.ConfigParser()
    config_parser.add_section(section_name)

    pcluster_config = get_mocked_pcluster_config(mocker)

    param_definition, param_type = get_param_definition(section_definition, param_key)
    param = param_type(section_definition.get("key"), section_label, param_key, param_definition, pcluster_config)
    param.value = param_value or param_definition.get("default")
    param.to_file(config_parser)

    if expected_value:
        assert_that(config_parser.has_option(section_name, param_key))
        assert_that(config_parser.get(section_name, param_key)).is_equal_to(expected_value)
    else:
        assert_that(config_parser.has_option(section_name, param_key)).is_false()
Exemple #4
0
def test_param_from_cfn(mocker, section_definition, param_key, cfn_params_dict,
                        expected_value):
    """Test conversion of simple parameters, that don't depends from multiple CFN parameters."""
    param_definition, param_type = get_param_definition(
        section_definition, param_key)
    cfn_params = []
    for cfn_key, cfn_value in cfn_params_dict.items():
        cfn_params.append({
            "ParameterKey": cfn_key,
            "ParameterValue": cfn_value
        })

    pcluster_config = get_mocked_pcluster_config(mocker)

    param = param_type(section_definition.get("key"), "default", param_key,
                       param_definition,
                       pcluster_config).from_cfn_params(cfn_params)

    assert_that(param.value, description="param key {0}".format(
        param_key)).is_equal_to(expected_value)