def test_absent(self): ''' Test to ensure that a memcached key is not present. ''' name = 'foo' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock_t = MagicMock(side_effect=[CommandExecutionError, 'salt', None, True, True, True]) with patch.dict(memcached.__salt__, {'memcached.get': mock_t, 'memcached.delete': mock_t}): self.assertDictEqual(memcached.absent(name), ret) comt = ("Value of key 'foo' ('salt') is not 'bar'") ret.update({'comment': comt, 'result': True}) self.assertDictEqual(memcached.absent(name, 'bar'), ret) comt = ("Key 'foo' does not exist") ret.update({'comment': comt}) self.assertDictEqual(memcached.absent(name), ret) with patch.dict(memcached.__opts__, {'test': True}): comt = ("Key 'foo' would be deleted") ret.update({'comment': comt, 'result': None}) self.assertDictEqual(memcached.absent(name), ret) with patch.dict(memcached.__opts__, {'test': False}): comt = ("Successfully deleted key 'foo'") ret.update({'comment': comt, 'result': True, 'changes': {'key deleted': 'foo', 'value': True}}) self.assertDictEqual(memcached.absent(name), ret)
def test_absent(self): ''' Test to ensure that a memcached key is not present. ''' name = 'foo' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock_t = MagicMock(side_effect=[ CommandExecutionError, 'salt', None, True, True, True ]) with patch.dict(memcached.__salt__, { 'memcached.get': mock_t, 'memcached.delete': mock_t }): self.assertDictEqual(memcached.absent(name), ret) comt = ("Value of key 'foo' ('salt') is not 'bar'") ret.update({'comment': comt, 'result': True}) self.assertDictEqual(memcached.absent(name, 'bar'), ret) comt = ("Key 'foo' does not exist") ret.update({'comment': comt}) self.assertDictEqual(memcached.absent(name), ret) with patch.dict(memcached.__opts__, {'test': True}): comt = ("Key 'foo' would be deleted") ret.update({'comment': comt, 'result': None}) self.assertDictEqual(memcached.absent(name), ret) with patch.dict(memcached.__opts__, {'test': False}): comt = ("Successfully deleted key 'foo'") ret.update({ 'comment': comt, 'result': True, 'changes': { 'key deleted': 'foo', 'value': True } }) self.assertDictEqual(memcached.absent(name), ret)
def test_absent(self): """ Test to ensure that a memcached key is not present. """ name = "foo" ret = {"name": name, "result": False, "comment": "", "changes": {}} mock_t = MagicMock(side_effect=[ CommandExecutionError, "salt", None, True, True, True ]) with patch.dict(memcached.__salt__, { "memcached.get": mock_t, "memcached.delete": mock_t }): self.assertDictEqual(memcached.absent(name), ret) comt = "Value of key 'foo' ('salt') is not 'bar'" ret.update({"comment": comt, "result": True}) self.assertDictEqual(memcached.absent(name, "bar"), ret) comt = "Key 'foo' does not exist" ret.update({"comment": comt}) self.assertDictEqual(memcached.absent(name), ret) with patch.dict(memcached.__opts__, {"test": True}): comt = "Key 'foo' would be deleted" ret.update({"comment": comt, "result": None}) self.assertDictEqual(memcached.absent(name), ret) with patch.dict(memcached.__opts__, {"test": False}): comt = "Successfully deleted key 'foo'" ret.update({ "comment": comt, "result": True, "changes": { "key deleted": "foo", "value": True }, }) self.assertDictEqual(memcached.absent(name), ret)