def test_get_calls_pool_request_for_counters(self): pool = mock.Mock(spec=riakcached.pools.Pool) pool.request.return_value = None, None, None pool.url = "http://127.0.0.1:8098" client = RiakClient("test_bucket", pool=pool) client.get("test", counter=True) self.assertTrue(pool.request.called) pool.request.assert_called_once_with( method="GET", url="http://127.0.0.1:8098/buckets/test_bucket/counters/test", )
def test_get_invalid_status_code(self): pool = mock.Mock(spec=riakcached.pools.Pool) pool.request.return_value = 302, "", {} pool.url = "http://127.0.0.1:8098" client = RiakClient("test_bucket", pool=pool) self.assertIsNone(client.get("test"))
def test_get_uses_deserializer(self): pool = mock.Mock(spec=riakcached.pools.Pool) pool.request.return_value = 200, "some data", {"content-type": "application/test"} pool.url = "http://127.0.0.1:8098" def deserializer(data): return "deserialized" client = RiakClient("test_bucket", pool=pool) client.add_deserializer("application/test", deserializer) result = client.get("test") self.assertEqual("deserialized", result)
def test_get_uses_deserializer(self): pool = mock.Mock(spec=riakcached.pools.Pool) pool.request.return_value = 200, "some data", { "content-type": "application/test" } pool.url = "http://127.0.0.1:8098" def deserializer(data): return "deserialized" client = RiakClient("test_bucket", pool=pool) client.add_deserializer("application/test", deserializer) result = client.get("test") self.assertEqual("deserialized", result)