Example #1
0
def test_editor_command_default(monkeypatch):
    """test editor with default"""
    def get_conf_path(*_args, **_kwargs):
        return None, []

    monkeypatch.setattr(cli, "get_conf_path", get_conf_path)
    _pre_logger_msgs, args = cli.parse_and_update([])
    assert args.editor_command == "vi +{line_number} {filename}"
Example #2
0
def test_editor_command_default(_mf1, monkeypatch):
    """test editor with default"""
    monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG",
                       f"{FIXTURES_DIR}/unit/cli/ansible-navigator_empty.yml")
    args = deepcopy(NavigatorConfiguration)
    _messages, exit_msgs = parse_and_update(params=[], args=args, initial=True)
    assert exit_msgs == []
    assert args.editor_command == "vi +{line_number} {filename}"
Example #3
0
def test_update_args(monkeypatch, test_fixtures_dir, given, argname, expected):
    """test the parse and update function"""
    def get_conf_path(*_args, **_kwargs):
        return os.path.join(test_fixtures_dir, "ansible-navigator.yml"), []

    monkeypatch.setattr(cli, "get_conf_path", get_conf_path)
    _pre_logger_msgs, args = cli.parse_and_update(given)
    result = vars(args)[argname]
    assert result == expected
def test_update_args_general(_mf1, monkeypatch, given, argname, expected):
    """test the parse and update function"""

    monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG",
                       f"{FIXTURES_DIR}/unit/cli/ansible-navigator.yml")
    args = deepcopy(NavigatorConfiguration)
    _messages, errors = parse_and_update(params=given, args=args, initial=True)
    assert errors == []
    result = args.entry(argname)
    assert result.value.current == expected, result
Example #5
0
def test_update_args_general(_mf1, monkeypatch, given, argname, expected):
    """test the parse and update function"""
    monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG",
                       f"{FIXTURES_DIR}/unit/cli/ansible-navigator.yml")
    args = deepcopy(NavigatorConfiguration)
    args.internals.initializing = True
    args.application_version = "test"
    _messages, exit_msgs = parse_and_update(params=given, args=args)
    assert not exit_msgs
    result = args.entry(argname)
    assert result.value.current == expected, result
Example #6
0
def test_no_term(monkeypatch):
    """test for err and hint w/o TERM"""
    monkeypatch.delenv("TERM")
    args = deepcopy(NavigatorConfiguration)
    args.internals.initializing = True
    params = []
    _messages, exit_msgs = parse_and_update(params=params, args=args)
    exit_msgs = [exit_msg.message for exit_msg in exit_msgs]
    expected = "TERM environment variable must be set"
    assert any(expected in exit_msg
               for exit_msg in exit_msgs), (expected, exit_msgs)
    expected = "Try again after setting the TERM environment variable"
    assert any(expected in exit_msg
               for exit_msg in exit_msgs), (expected, exit_msgs)
Example #7
0
def test_hints(monkeypatch, locked_directory, valid_container_engine, data):
    """test the hints don't generate a traceboack"""
    monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG",
                       f"{FIXTURES_DIR}/unit/cli/ansible-navigator_empty.yml")
    args = deepcopy(NavigatorConfiguration)
    command = data.command.format(locked_directory=locked_directory)
    params = shlex.split(command)
    if data.set_ce:
        params += ["--ce", valid_container_engine]

    _messages, exit_msgs = parse_and_update(params=params,
                                            args=args,
                                            initial=True)
    expected = f"{data.prefix} {data.expected}"
    exit_msgs = [exit_msg.message for exit_msg in exit_msgs]
    assert any(expected in exit_msg
               for exit_msg in exit_msgs), (expected, exit_msgs)