def test_valid_yaml(settings_samples: Tuple[str, str]):
    """Simple test to ensure the sample is valid yaml.

    :param settings_samples: The sample setting
    """
    commented, uncommented = settings_samples
    settings_contents = yaml.load(commented, Loader=Loader)
    assert settings_contents
    settings_contents = yaml.load(uncommented, Loader=Loader)
    assert settings_contents
Example #2
0
def test_schema_sample_full_package_data(schema_dict: SettingsSchemaType):
    """Check the settings file used as a sample against the schema.

    :param schema_dict: The json schema as a dictionary
    """
    settings = deepcopy(NavigatorConfiguration)
    commented, uncommented = to_sample(settings=settings)
    settings_dict = yaml.load(commented, Loader=Loader)
    validate(instance=settings_dict, schema=schema_dict)
    settings_dict = yaml.load(uncommented, Loader=Loader)
    validate(instance=settings_dict, schema=schema_dict)
Example #3
0
def _generate_config(params=None,
                     setting_file_name=None,
                     initial=True) -> GenerateConfigResponse:
    """Generate a configuration given a settings file"""
    if params is None:
        params = []

    if setting_file_name:
        settings_file_path = os.path.join(TEST_FIXTURE_DIR, setting_file_name)
        with open(file=settings_file_path, encoding="utf-8") as fh:
            try:
                settings_contents = yaml.load(fh, Loader=Loader)
            except yaml.parser.ParserError:
                # let the configuration subsystem catch the invalid yaml file
                settings_contents = {}
    else:
        settings_file_path = ""
        settings_contents = {}

    # make a deep copy here to ensure we do not modify the original
    application_configuration = deepcopy(NavigatorConfiguration)
    application_configuration.internals.initializing = initial
    application_configuration.application_version = "test"
    application_configuration.internals.settings_file_path = settings_file_path or None
    configurator = Configurator(
        application_configuration=application_configuration,
        params=params,
    )
    messages, exit_messages = configurator.configure()
    return GenerateConfigResponse(
        messages=messages,
        exit_messages=exit_messages,
        application_configuration=application_configuration,
        settings_contents=settings_contents,
    )
Example #4
0
def test_schema_sample_full_tests(schema_dict: SettingsSchemaType):
    """Check the full settings file against the schema.

    :param schema_dict: The json schema as a dictionary
    """
    settings_file = Path(TEST_FIXTURE_DIR, "ansible-navigator.yml")
    with settings_file.open(encoding="utf-8") as fh:
        settings_contents = yaml.load(fh, Loader=Loader)
    validate(instance=settings_contents, schema=schema_dict)
def test_full_settings_file():
    """Test using a full settings file"""
    settings_file_path = os.path.join(TEST_FIXTURE_DIR,
                                      "ansible-navigator.yml")
    with open(file=settings_file_path, encoding="utf-8") as fh:
        settings_contents = yaml.load(fh, Loader=Loader)
    for entry in NavigatorConfiguration.entries:
        path = entry.settings_file_path("ansible-navigator")
        expected = settings_contents
        for key in path.split("."):
            expected = expected[key]
Example #6
0
def test_schema_sample_wrong(schema_dict: SettingsSchemaType):
    """Check the broken settings file against the schema.

    :param schema_dict: The json schema as a dictionary
    """
    settings_file = Path(TEST_FIXTURE_DIR, "ansible-navigator_no_app.yml")
    with settings_file.open(encoding="utf-8") as fh:
        settings_contents = yaml.load(fh, Loader=Loader)
    with pytest.raises(ValidationError) as exc:
        validate(instance=settings_contents, schema=schema_dict)
    assert "'non_app' is not one of ['builder'" in str(exc)
Example #7
0
def settings_env_var_to_full(
    settings_samples: Tuple[str, str],
    tmp_path: Path,
    monkeypatch: pytest.MonkeyPatch,
) -> Tuple[Path, SettingsFileType]:
    """Set the settings environment variable to a full sample settings file in a tmp path."""
    _commented, uncommented = settings_samples
    settings_contents = yaml.load(uncommented, Loader=Loader)
    settings_path = tmp_path / "ansible-navigator.yml"
    serialize_write_file(
        content=settings_contents,
        content_view=ContentView.NORMAL,
        file_mode="w",
        file=settings_path,
        serialization_format=SerializationFormat.YAML,
    )
    # The sample has volume mounts, so let's not exit because they doesn't exit
    root = settings_contents["ansible-navigator"]
    ee_root = root["execution-environment"]
    for volume_mount in ee_root["volume-mounts"]:
        Path(volume_mount["src"]).mkdir(exist_ok=True)

    monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG", str(settings_path))
    return settings_path, settings_contents