def test_increment(self): """ Test if it increment 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 incr(self, key, delta): """ Mock of incr 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.increment("salt"), "salt") self.assertRaises( SaltInvocationError, memcached.increment, "salt", delta="sa" )
def test_increment(self): ''' Test if it increment 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 incr(self, key, delta): """ Mock of incr 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.increment('salt'), 'salt') self.assertRaises(SaltInvocationError, memcached.increment, 'salt', delta='sa')