def test_absent(self): ''' Test various cases for win_path.absent ''' ret_base = {'name': NAME, 'result': True, 'changes': {}} def _mock(retval): # Return a new MagicMock for each test case return MagicMock(side_effect=retval) # We don't really want to run the remove func with patch.dict(win_path.__salt__, {'win_path.remove': Mock()}): # Test mode OFF with patch.dict(win_path.__opts__, {'test': False}): # Test already absent with patch.dict(win_path.__salt__, {'win_path.exists': _mock([False])}): ret = copy.deepcopy(ret_base) ret['comment'] = '{0} is not in the PATH'.format(NAME) ret['result'] = True self.assertDictEqual(win_path.absent(NAME), ret) # Test successful removal with patch.dict(win_path.__salt__, {'win_path.exists': _mock([True, False])}): ret = copy.deepcopy(ret_base) ret['comment'] = 'Removed {0} from the PATH'.format(NAME) ret['changes']['removed'] = NAME ret['result'] = True self.assertDictEqual(win_path.absent(NAME), ret) # Test unsucessful removal with patch.dict(win_path.__salt__, {'win_path.exists': _mock([True, True])}): ret = copy.deepcopy(ret_base) ret['comment'] = 'Failed to remove {0} from the PATH'.format(NAME) ret['result'] = False self.assertDictEqual(win_path.absent(NAME), ret) # Test mode ON with patch.dict(win_path.__opts__, {'test': True}): # Test already absent with patch.dict(win_path.__salt__, {'win_path.exists': _mock([False])}): ret = copy.deepcopy(ret_base) ret['comment'] = '{0} is not in the PATH'.format(NAME) ret['result'] = True self.assertDictEqual(win_path.absent(NAME), ret) # Test the test-mode return with patch.dict(win_path.__salt__, {'win_path.exists': _mock([True])}): ret = copy.deepcopy(ret_base) ret['comment'] = '{0} would be removed from the PATH'.format(NAME) ret['result'] = None self.assertDictEqual(win_path.absent(NAME), ret)
def test_absent(self): ''' Test to remove the directory from the SYSTEM path ''' ret = {'name': 'salt', 'changes': {}, 'result': None, 'comment': ''} mock = MagicMock(return_value=False) with patch.dict(win_path.__salt__, {"win_path.exists": mock}): with patch.dict(win_path.__opts__, {"test": True}): ret.update({'comment': 'salt is not in the PATH'}) self.assertDictEqual(win_path.absent('salt'), ret) with patch.dict(win_path.__opts__, {"test": False}): mock = MagicMock(return_value=True) with patch.dict(win_path.__salt__, {"win_path.remove": mock}): ret.update({'result': True}) self.assertDictEqual(win_path.absent('salt'), ret)
def test_absent(self): ''' Test to remove the directory from the SYSTEM path ''' ret = {'name': 'salt', 'changes': {}, 'result': None, 'comment': ''} mock = MagicMock(return_value=False) with patch.dict(win_path.__salt__, {"win_path.exists": mock}): with patch.dict(win_path.__opts__, {"test": True}): ret.update({'comment': 'salt is not in the PATH'}) self.assertDictEqual(win_path.absent('salt'), ret) with patch.dict(win_path.__opts__, {"test": False}): mock = MagicMock(return_value=True) with patch.dict(win_path.__salt__, {"win_path.remove": mock}): ret.update({'result': True}) self.assertDictEqual(win_path.absent('salt'), ret)
def test_absent(name): """ Test various cases for win_path.absent """ ret_base = {"name": name, "result": True, "changes": {}} def _mock(retval): # Return a new MagicMock for each test case return MagicMock(side_effect=retval) # We don't really want to run the remove func with patch.dict(win_path.__salt__, {"win_path.remove": Mock()}): # Test mode OFF with patch.dict(win_path.__opts__, {"test": False}): # Test already absent with patch.dict(win_path.__salt__, {"win_path.exists": _mock([False])}): ret = copy.deepcopy(ret_base) ret["comment"] = "{} is not in the PATH".format(name) ret["result"] = True assert win_path.absent(name) == ret # Test successful removal with patch.dict(win_path.__salt__, {"win_path.exists": _mock([True, False])}): ret = copy.deepcopy(ret_base) ret["comment"] = "Removed {} from the PATH".format(name) ret["changes"]["removed"] = name ret["result"] = True assert win_path.absent(name) == ret # Test unsucessful removal with patch.dict(win_path.__salt__, {"win_path.exists": _mock([True, True])}): ret = copy.deepcopy(ret_base) ret["comment"] = "Failed to remove {} from the PATH".format( name) ret["result"] = False assert win_path.absent(name) == ret # Test mode ON with patch.dict(win_path.__opts__, {"test": True}): # Test already absent with patch.dict(win_path.__salt__, {"win_path.exists": _mock([False])}): ret = copy.deepcopy(ret_base) ret["comment"] = "{} is not in the PATH".format(name) ret["result"] = True assert win_path.absent(name) == ret # Test the test-mode return with patch.dict(win_path.__salt__, {"win_path.exists": _mock([True])}): ret = copy.deepcopy(ret_base) ret["comment"] = "{} would be removed from the PATH".format( name) ret["result"] = None assert win_path.absent(name) == ret