コード例 #1
0
    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",
        )
コード例 #2
0
    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",
        )
コード例 #3
0
    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"))
コード例 #4
0
    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"))
コード例 #5
0
    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)
コード例 #6
0
    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)