def test_get_set_non_ascii_value(): client = MockMemcacheClient() assert client.get(b"hello") is None # This is the value of msgpack.packb('non_ascii') non_ascii_str = b'\xa9non_ascii' client.set(b"hello", non_ascii_str) assert client.get(b"hello") == non_ascii_str
def test_incr_decr(): client = MockMemcacheClient() client.add(b"k", 2) client.incr(b"k", 4) tools.assert_equal(client.get(b"k"), 6) client.decr(b"k", 2) tools.assert_equal(client.get(b"k"), 4)
def test_incr_decr(): client = MockMemcacheClient() client.add(b"k", 2) client.incr(b"k", 4) assert client.get(b"k") == 6 client.decr(b"k", 2) assert client.get(b"k") == 4
def test_prepand_append(): client = MockMemcacheClient() client.set(b"k", "1") client.append(b"k", "a") client.prepend(b"k", "p") assert client.get(b"k") == b"p1a"
def test_prepand_append(): client = MockMemcacheClient() client.set(b"k", '1') client.append(b"k", 'a') client.prepend(b"k", 'p') assert client.get(b"k") == b'p1a'
def test_incr_decr(): client = MockMemcacheClient() client.add("k", 2) client.incr("k", 4) tools.assert_equal(client.get("k"), 6) client.decr("k", 2) tools.assert_equal(client.get("k"), 4)
def test_add(): client = MockMemcacheClient() client.add(b"k", 2) tools.assert_equal(client.get(b"k"), 2) client.add(b"k", 25) tools.assert_equal(client.get(b"k"), 2)
def test_delete(): client = MockMemcacheClient() client.add(b"k", 2) tools.assert_equal(client.get(b"k"), 2) client.delete(b"k") tools.assert_equal(client.get(b"k"), None)
def test_add(): client = MockMemcacheClient() client.add(b"k", 2) assert client.get(b"k") == 2 client.add(b"k", 25) assert client.get(b"k") == 2
def test_delete(): client = MockMemcacheClient() client.add(b"k", 2) assert client.get(b"k") == 2 client.delete(b"k") assert client.get(b"k") is None
def test_get_many_set_many(): client = MockMemcacheClient() client.set("h", 1) tools.assert_equal(client.get_many("hello"), {"h" : 1}) client.set_many(dict(h=1, e=2, l=3)) tools.assert_equal(client.get_many("hello"), dict(h=1, e=2, l=3))
def __init__( self, servers: Optional[Tuple[str, int]] = None, connect_timeout=None, read_timeout=None, serde=None, testing=False, ignore_exc=False, ): client_kwargs = dict( connect_timeout=connect_timeout, timeout=read_timeout, serde=serde or JsonSerializerDeserializer(), ignore_exc=ignore_exc, ) if testing: self.client = MockMemcacheClient( server=None, **client_kwargs, ) else: self.client = HashClient( servers=servers, **client_kwargs, )
def test_get_many_set_many(): client = MockMemcacheClient() client.set(b"h", 1) result = client.get_many([b"h", b"e", b"l", b"o"]) assert result == {b"h": 1} # Convert keys into bytes d = {k.encode("ascii"): v for k, v in dict(h=1, e=2, z=3).items()} client.set_many(d) assert client.get_many([b"h", b"e", b"z", b"o"]) == d
def test_get_many_set_many(): client = MockMemcacheClient() client.set(b"h", 1) tools.assert_equal(client.get_many([b"h", b"e", b"l", b"o"]), {b"h": 1}) # Convert keys into bytes d = dict( (k.encode('ascii'), v) for k, v in six.iteritems(dict(h=1, e=2, l=3))) client.set_many(d) tools.assert_equal(client.get_many([b"h", b"e", b"l", b"o"]), d)
def test_get_many_set_many(): client = MockMemcacheClient() client.set(b"h", 1) result = client.get_many([b"h", b"e", b"l", b"o"]) assert result == {b"h": 1} # Convert keys into bytes d = dict( (k.encode('ascii'), v) for k, v in six.iteritems(dict(h=1, e=2, l=3))) client.set_many(d) assert client.get_many([b"h", b"e", b"l", b"o"]) == d
def memcache(self): servers = config.get("memcache_servers", None) if servers: return olmemcache.Client(servers) else: web.debug("Could not find memcache_servers in the configuration. Used dummy memcache.") try: import mockcache return mockcache.Client() except ImportError: from pymemcache.test.utils import MockMemcacheClient return MockMemcacheClient()
def test_get_set_non_ascii_value(): client = MockMemcacheClient() assert client.get(b"hello") is None # This is the value of msgpack.packb('non_ascii') non_ascii_str = b"\xa9non_ascii" client.set(b"hello", non_ascii_str) assert client.get(b"hello") == non_ascii_str
def _get_memcache(self): if self._memcache is None: servers = config.get("memcache_servers") if servers: self._memcache = memcache.Client(servers) else: web.debug("Could not find memcache_servers in the configuration. Used dummy memcache.") try: import mockcache # Only supports legacy Python self._memcache = mockcache.Client() except ImportError: # Python 3 from pymemcache.test.utils import MockMemcacheClient self._memcache = MockMemcacheClient() return self._memcache
def test_get_many_set_many_non_ascii_values(): client = MockMemcacheClient() # These are the values of calling msgpack.packb() on '1', '2', and '3' non_ascii_1 = b'\xa11' non_ascii_2 = b'\xa12' non_ascii_3 = b'\xa13' client.set(b"h", non_ascii_1) result = client.get_many([b"h", b"e", b"l", b"o"]) assert result == {b"h": non_ascii_1} # Convert keys into bytes d = dict((k.encode('ascii'), v) for k, v in six.iteritems( dict(h=non_ascii_1, e=non_ascii_2, z=non_ascii_3))) client.set_many(d) assert client.get_many([b"h", b"e", b"z", b"o"]) == d
def test_get_many_set_many_non_ascii_values(): client = MockMemcacheClient() # These are the values of calling msgpack.packb() on '1', '2', and '3' non_ascii_1 = b"\xa11" non_ascii_2 = b"\xa12" non_ascii_3 = b"\xa13" client.set(b"h", non_ascii_1) result = client.get_many([b"h", b"e", b"l", b"o"]) assert result == {b"h": non_ascii_1} # Convert keys into bytes d = { k.encode("ascii"): v for k, v in dict(h=non_ascii_1, e=non_ascii_2, z=non_ascii_3).items() } client.set_many(d) assert client.get_many([b"h", b"e", b"z", b"o"]) == d
def make_client(self, mock_socket_values, **kwargs): client = MockMemcacheClient(None, **kwargs) client.sock = MockSocket(list(mock_socket_values)) return client
def make_client(self, mock_socket_values, serializer=None): client = MockMemcacheClient(None, serializer=serializer) client.sock = MockSocket(list(mock_socket_values)) return client
def test_get_set(): client = MockMemcacheClient() assert client.get(b"hello") is None client.set(b"hello", 12) assert client.get(b"hello") == 12
def memcache(): return MockMemcacheClient()
def test_get_set(): client = MockMemcacheClient() tools.assert_equal(client.get(b"hello"), None) client.set(b"hello", 12) tools.assert_equal(client.get(b"hello"), 12)