1from basetestcase import BaseTestCase
2from membase.helper.cluster_helper import ClusterOperationHelper
3from sdk_client import SDKClient
4
5class SDKClientTests(BaseTestCase):
6    """ Class for defining tests for python sdk """
7
8    def setUp(self):
9        super(SDKClientTests, self).setUp()
10        self.cluster.rebalance(self.servers[:self.num_servers], self.servers[1:self.num_servers], [])
11        credentials = self.input.membase_settings
12        self.log = logger.Logger.get_logger()
13        credentials = self.input.membase_settings
14        self.log.info("==============  SDKClientTests setup was finished for test #{0} {1} =============="\
15                      .format(self.case_number, self._testMethodName))
16    def tearDown(self):
17        super(SDKClientTests, self).tearDown()
18
19    def test_sdk_client(self):
20        """
21            Test SDK Client Calls
22        """
23        client = SDKClient(scheme="couchbase",hosts = [self.master], bucket = "default")
24        client.remove("1",quiet=True)
25        client.insert("1","{1:2}")
26        val, flag, cas = client.get("1")
27        self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas))
28        client.upsert("1","{1:3}")
29        client.touch("1",ttl=100)
30        val, flag, cas = client.get("1")
31        self.assertTrue(val == "{1:3}")
32        self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas))
33        client.remove("1",cas = cas)
34        client.incr("key", delta=20, initial=5)
35        val, flag, cas = client.get("key")
36        self.assertTrue(val == 5)
37        self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas))
38        client.incr("key", delta=20, initial=5)
39        val, flag, cas = client.get("key")
40        self.assertTrue(val == 25)
41        self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas))
42        client.decr("key", delta=20, initial=5)
43        val, flag, cas = client.get("key")
44        self.assertTrue(val == 5)
45        print val, flag, cas
46        client.upsert("key1","document1")
47        client.upsert("key2","document2")
48        client.upsert("key3","document3")
49        set = client.get_multi(["key1","key2"])
50        self.log.info(set)
51        client.upsert_multi({"key1":"{1:2}","key2":"{3:2}"})
52        set = client.get_multi(["key1","key2","key3"])
53        self.log.info(set)
54        client.touch_multi(["key1","key2","key3"],ttl=200)
55        set = client.get_multi(["key1","key2","key3"])
56        self.log.info(set)
57        set = client.get_multi(["key1","key2","key3"],replica=True)
58        self.log.info(set)
59        data = client.observe("key1")
60        self.log.info(data)
61        data = client.observe_multi(["key1","key2"])
62        self.log.info(data)
63        stats = client.stats(["key1"])
64        self.log.info(stats)
65        client.close()
66