コード例 #1
0
def test_absent():
    """
    Test to ensure a sysrc variable is absent.
    """
    ret = {"name": "salt", "changes": {}, "result": True, "comment": ""}
    mock = MagicMock(side_effect=[None, True, True])
    mock1 = MagicMock(return_value=True)
    with patch.dict(sysrc.__salt__, {
            "sysrc.get": mock,
            "sysrc.remove": mock1
    }):
        ret.update({"comment": '"salt" is already absent.'})
        assert sysrc.absent("salt") == ret

        with patch.dict(sysrc.__opts__, {"test": True}):
            ret.update({
                "changes": {
                    "new": '"salt" will be removed.',
                    "old": True
                },
                "comment": '"salt" will be removed!',
                "result": None,
            })
            assert sysrc.absent("salt") == ret

        with patch.dict(sysrc.__opts__, {"test": False}):
            ret.update({
                "changes": {
                    "new": True,
                    "old": True
                },
                "comment": '"salt" was removed!',
                "result": True,
            })
            assert sysrc.absent("salt") == ret
コード例 #2
0
ファイル: test_sysrc.py プロジェクト: morinap/salt-1
    def test_absent(self):
        '''
            Test to ensure a sysrc variable is absent.
        '''
        ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''}
        mock = MagicMock(side_effect=[None, True, True])
        mock1 = MagicMock(return_value=True)
        with patch.dict(sysrc.__salt__, {
                "sysrc.get": mock,
                "sysrc.remove": mock1
        }):
            ret.update({'comment': '"salt" is already absent.'})
            self.assertDictEqual(sysrc.absent('salt'), ret)

            with patch.dict(sysrc.__opts__, {"test": True}):
                ret.update({
                    'changes': {
                        'new': '"salt" will be removed.',
                        'old': True
                    },
                    'comment': '"salt" will be removed!',
                    'result': None
                })
                self.assertDictEqual(sysrc.absent('salt'), ret)

            with patch.dict(sysrc.__opts__, {"test": False}):
                ret.update({
                    'changes': {
                        'new': True,
                        'old': True
                    },
                    'comment': '"salt" was removed!',
                    'result': True
                })
                self.assertDictEqual(sysrc.absent('salt'), ret)
コード例 #3
0
ファイル: sysrc_test.py プロジェクト: DaveQB/salt
    def test_absent(self):
        '''
            Test to ensure a sysrc variable is absent.
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': True,
               'comment': ''}
        mock = MagicMock(side_effect=[None, True, True])
        mock1 = MagicMock(return_value=True)
        with patch.dict(sysrc.__salt__, {"sysrc.get": mock,
                                         "sysrc.remove": mock1}):
            ret.update({'comment': '"salt" is already absent.'})
            self.assertDictEqual(sysrc.absent('salt'), ret)

            with patch.dict(sysrc.__opts__, {"test": True}):
                ret.update({'changes': {'new': '"salt" will be removed.',
                                        'old': True},
                            'comment': '"salt" will be removed!',
                            'result': None})
                self.assertDictEqual(sysrc.absent('salt'), ret)

            with patch.dict(sysrc.__opts__, {"test": False}):
                ret.update({'changes': {'new': True, 'old': True},
                            'comment': '"salt" was removed!',
                            'result': True})
                self.assertDictEqual(sysrc.absent('salt'), ret)