Beispiel #1
0
 def test_argparse_raise_exception(self):
     """
     Test argparse raise exception.
     """
     msg = "not enough memory, get system upgrade"
     argparse = spacecmd.argumentparser.SpacecmdArgumentParser()
     with pytest.raises(Exception) as exc:
         argparse.error(msg)
     assert msg in exc2str(exc)
Beispiel #2
0
    def test_string_to_bool_false_type(self):
        """
        Test string conversion to boolean handling false type

        :return:
        """
        for value in [b"", 1, {}, [], ()]:
            with pytest.raises(IOError) as exc:
                spacecmd.utils.string_to_bool(value)
            assert "Parameter" in exc2str(exc)
Beispiel #3
0
    def test_custominfo_updatekey_noarg_name(self, shell):
        """
        Test do_custominfo_updatekey with no arguments falls to the interactive prompt.
        """
        shell.client.system.custominfo.updateKey = MagicMock()
        prompt = MagicMock(side_effect=Exception("interactive mode"))
        with patch("spacecmd.custominfo.prompt_user", prompt):
            with pytest.raises(Exception) as exc:
                custominfo.do_custominfo_updatekey(shell, "")

        assert "interactive mode" in exc2str(exc)
Beispiel #4
0
    def test_custominfo_updatekey_keyonly_arg(self, shell):
        """
        Test do_custominfo_updatekey description is taken interactively.
        """
        shell.client.system.custominfo.updateKey = MagicMock()
        prompt = MagicMock(
            side_effect=[Exception("interactive mode for descr")])
        with patch("spacecmd.custominfo.prompt_user", prompt):
            with pytest.raises(Exception) as exc:
                custominfo.do_custominfo_updatekey(shell, "keyname")

        assert "interactive mode for descr" in exc2str(exc)
Beispiel #5
0
    def test_do_custominfo_createkey_no_keyname(self, shell):
        """
        Test do_custominfo_createkey do not break on no key name provided, falling back to interactive mode.
        """
        shell.client.system.custominfo.createKey = MagicMock()
        prompter = MagicMock(side_effect=["", "", Exception("Empty key")])

        with patch("spacecmd.custominfo.prompt_user", prompter):
            with pytest.raises(Exception) as exc:
                custominfo.do_custominfo_createkey(shell, "")

        assert "Empty key" in exc2str(exc)
Beispiel #6
0
 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)
Beispiel #7
0
    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)
Beispiel #8
0
    def test_do_custominfo_deletekey_noargs(self, shell):
        """
        Test do_custominfo_deletekey shows help on no args.
        """
        errmsg = "No arguments passed"
        shell.client.system.custominfo.deleteKey = MagicMock()
        shell.do_custominfo_listkeys = MagicMock()
        shell.help_custominfo_deletekey = MagicMock(
            side_effect=Exception(errmsg))
        shell.user_confirm = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.custominfo.logging", logger):
            with pytest.raises(Exception) as exc:
                custominfo.do_custominfo_deletekey(shell, "")

        assert errmsg in exc2str(exc)
Beispiel #9
0
    def test_do_custominfo_details_noarg(self, shell):
        """
        Test do_custominfo_details shows help when no arguments has been passed.
        """
        keylist = ["some_key", "some_other_key", "this_key_stays"]
        shell.help_custominfo_details = MagicMock(
            side_effect=Exception("Help info"))
        shell.client.system.custominfo.listAllKeys = MagicMock()
        shell.do_custominfo_listkeys = MagicMock(return_value=keylist)
        logger = MagicMock()

        with patch("spacecmd.custominfo.logging", logger):
            with pytest.raises(Exception) as exc:
                custominfo.do_custominfo_details(shell, "")

        assert "Help info" in exc2str(exc)
        assert not logger.debug.called
        assert not logger.error.called
        assert not shell.client.system.custominfo.listAllKeys.called