def test_shell_precmd_exit_keywords(self): """ Test 'precmd' method of the shell on exit keywords. """ options = MagicMock() options.nohistory = True shell = SpacewalkShell(options, "", None) shell.config["server"] = "" for cmd in ["exit", "quit", "eof"]: with pytest.raises(Exception) as exc: shell.precmd(cmd) assert "Exit attempt" in exc2str(exc)
def test_shell_precmd_help_keyword(self): """ Test 'precmd' method of the shell on --help/-h arguments. """ options = MagicMock() options.nohistory = True shell = SpacewalkShell(options, "", None) shell.config["server"] = "" shell.session = True assert shell.precmd("system_list --help") == "help system_list" assert shell.precmd("system_list -h") == "help system_list"
def test_shell_precmd_session_login(self): """ Test 'precmd' method of the shell on session login. """ options = MagicMock() options.nohistory = True shell = SpacewalkShell(options, "", None) shell.config["server"] = "" shell.do_login = MagicMock(side_effect=Exception("login attempt")) with pytest.raises(Exception) as exc: shell.precmd("system_list") assert "login attempt" in exc2str(exc)
def test_shell_precmd_empty_line(self): """ Test 'precmd' method of the shell on empty line. """ options = MagicMock() options.nohistory = True shell = SpacewalkShell(options, "", None) shell.config["server"] = "" assert shell.precmd("") == ""
def test_shell_precmd_common_keywords(self): """ Test 'precmd' method of the shell on common keywords, e.g. login, logout, clear etc. """ options = MagicMock() options.nohistory = True shell = SpacewalkShell(options, "", None) shell.config["server"] = "" for cmd in ["help", "login", "logout", "whoami", "history", "clear"]: assert shell.precmd(cmd) == cmd
def test_shell_precmd_history(self): """ Test 'precmd' method getting history item. """ options = MagicMock() options.nohistory = True shell = SpacewalkShell(options, "", None) shell.config["server"] = "" shell.session = True assert shell.precmd("!!") == "repeated item"
def test_shell_precmd_one_char_cmd(self): """ Test 'precmd' method one char. """ options = MagicMock() options.nohistory = True shell = SpacewalkShell(options, "", None) shell.config["server"] = "" shell.session = True assert shell.precmd("x") == "x"