예제 #1
0
    def test_do_custominfo_details_keydetails_na(self, shell):
        """
        Test do_custominfo_details prints key details not available in format.
        """
        shell.SEPARATOR = "***"
        shell.client.system.custominfo.listAllKeys = MagicMock(return_value=[
            {
                "label": "key_one"
            },
            {
                "label": "key_two"
            },
        ])
        shell.do_custominfo_listkeys = MagicMock(
            return_value=["key_one", "key_two"])
        logger = MagicMock()
        mprint = MagicMock()

        with patch("spacecmd.custominfo.logging", logger):
            with patch("spacecmd.custominfo.print", mprint):
                custominfo.do_custominfo_details(shell, "key*")

        expectations = [
            'Label:        key_one', 'Description:  N/A', 'Modified:     N/A',
            'System Count: 0', '***', 'Label:        key_two',
            'Description:  N/A', 'Modified:     N/A', 'System Count: 0'
        ]

        assert shell.client.system.custominfo.listAllKeys.called
        assert mprint.called
        for idx, call in enumerate(mprint.call_args_list):
            assert call[0][0] == expectations[idx]
예제 #2
0
    def test_do_custominfo_details_keydetails_notfound(self, shell):
        """
        Test do_custominfo_details nothing happens if keydetails missing.
        """
        shell.client.system.custominfo.listAllKeys = MagicMock()
        shell.do_custominfo_listkeys = MagicMock(
            return_value=["key_one", "key_two"])
        logger = MagicMock()
        mprint = MagicMock()

        with patch("spacecmd.custominfo.logging", logger):
            with patch("spacecmd.custominfo.print", mprint):
                custominfo.do_custominfo_details(shell, "key*")

        assert shell.client.system.custominfo.listAllKeys.called
        assert not mprint.called
예제 #3
0
    def test_do_custominfo_details_no_key(self, shell):
        """
        Test do_custominfo_details shows error to the log if key name doesn't match.
        """
        shell.client.system.custominfo.listAllKeys = MagicMock()
        shell.do_custominfo_listkeys = MagicMock(
            return_value=["key_one", "key_two"])
        logger = MagicMock()
        mprint = MagicMock()

        with patch("spacecmd.custominfo.logging", logger):
            with patch("spacecmd.custominfo.print", mprint):
                custominfo.do_custominfo_details(shell, "keyname")

        assert not shell.client.system.custominfo.listAllKeys.called
        assert logger.debug.call_args_list[0][0][
            0] == "customkey_details called with args: 'keyname', keys: ''."
        assert logger.error.call_args_list[0][0][
            0] == "No keys matched argument 'keyname'."
예제 #4
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