コード例 #1
0
ファイル: win_system_test.py プロジェクト: lvg01/salt.old
    def test_computer_name(self):
        '''
            Test to manage the computer's name
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': True,
               'comment': ''}
        mock = MagicMock(return_value='salt')
        with patch.dict(win_system.__salt__,
                        {"system.get_computer_name": mock}):
            mock = MagicMock(side_effect=[None, 'SALT', 'Stack', 'stack'])
            with patch.dict(win_system.__salt__,
                            {"system.get_pending_computer_name": mock}):
                ret.update({'comment': "Computer name already set to 'salt'"})
                self.assertDictEqual(win_system.computer_name('salt'), ret)

                ret.update({'comment': "The current computer name"
                            " is 'salt', but will be changed to 'salt' on"
                            " the next reboot"})
                self.assertDictEqual(win_system.computer_name('salt'), ret)

                with patch.dict(win_system.__opts__, {"test": True}):
                    ret.update({'result': None, 'comment': "Computer name will"
                                " be changed to 'salt'"})
                    self.assertDictEqual(win_system.computer_name('salt'), ret)

                with patch.dict(win_system.__opts__, {"test": False}):
                    mock = MagicMock(return_value=False)
                    with patch.dict(win_system.__salt__,
                                    {"system.set_computer_name": mock}):
                        ret.update({'comment': "Unable to set computer name"
                                    " to 'salt'", 'result': False})
                        self.assertDictEqual(win_system.computer_name('salt'),
                                             ret)
コード例 #2
0
    def test_computer_name(self):
        """
            Test to manage the computer's name
        """
        ret = {"name": "salt", "changes": {}, "result": True, "comment": ""}
        mock = MagicMock(return_value="salt")
        with patch.dict(win_system.__salt__,
                        {"system.get_computer_name": mock}):
            mock = MagicMock(side_effect=[None, "SALT", "Stack", "stack"])
            with patch.dict(win_system.__salt__,
                            {"system.get_pending_computer_name": mock}):
                ret.update({"comment": "Computer name already set to 'salt'"})
                self.assertDictEqual(win_system.computer_name("salt"), ret)

                ret.update({
                    "comment":
                    "The current computer name"
                    " is 'salt', but will be changed to 'salt' on"
                    " the next reboot"
                })
                self.assertDictEqual(win_system.computer_name("salt"), ret)

                with patch.dict(win_system.__opts__, {"test": True}):
                    ret.update({
                        "result":
                        None,
                        "comment":
                        "Computer name will"
                        " be changed to 'salt'",
                    })
                    self.assertDictEqual(win_system.computer_name("salt"), ret)

                with patch.dict(win_system.__opts__, {"test": False}):
                    mock = MagicMock(return_value=False)
                    with patch.dict(win_system.__salt__,
                                    {"system.set_computer_name": mock}):
                        ret.update({
                            "comment": "Unable to set computer name"
                            " to 'salt'",
                            "result": False,
                        })
                        self.assertDictEqual(win_system.computer_name("salt"),
                                             ret)