def test_decrement(self): """ Test if it decrement the value of a key """ class MockMemcache(object): """ Mock of memcache """ def __init__(self): self.key = None @staticmethod def get_stats(): """ Mock of stats method """ return [("127.0.0.1:11211 (1)", {})] def get(self, key): """ Mock of get method """ self.key = key return 1 def decr(self, key, delta): """ Mock of decr method """ self.key = key if not isinstance(delta, integer_types): raise SaltInvocationError("Delta value must be an integer") return key with patch.object( memcached, "_connect", MagicMock(return_value=MockMemcache()) ): self.assertEqual(memcached.decrement("salt"), "salt") self.assertRaises( SaltInvocationError, memcached.decrement, "salt", delta="sa" )
def test_decrement(self): ''' Test if it decrement the value of a key ''' class MockMemcache(object): """ Mock of memcache """ def __init__(self): self.key = None @staticmethod def get_stats(): """ Mock of stats method """ return [('127.0.0.1:11211 (1)', {})] def get(self, key): """ Mock of get method """ self.key = key return 1 def decr(self, key, delta): """ Mock of decr method """ self.key = key if not isinstance(delta, integer_types): raise SaltInvocationError('Delta value must be an integer') return key with patch.object(memcached, '_connect', MagicMock(return_value=MockMemcache())): self.assertEqual(memcached.decrement('salt'), 'salt') self.assertRaises(SaltInvocationError, memcached.decrement, 'salt', delta='sa')