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
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)
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)