コード例 #1
0
 def testMultiHost(self):
     info = self.cluster_info
     cs = ConnectionString.parse(self.make_connargs()['connection_string'])
     cs.hosts = [ info.host + ':' + '10', info.host + ':' + str(info.port) ]
     cb = self.make_connection(connection_string=cs.encode())
     d = cb.on_connect()
     d.addCallback(lambda x: self.assertTrue(cb.connected))
     return d
コード例 #2
0
 def _get_connstr_and_bucket_name(
         self,
         args,  # type: List[Any]
         kwargs):
     connstr = args.pop(0) if args else kwargs.pop('connection_string')
     connstr_nobucket = ConnectionString.parse(connstr)
     bucket = connstr_nobucket.bucket
     connstr_nobucket.bucket = None
     return connstr_nobucket, bucket
コード例 #3
0
    def test_server_not_found(self):
        connargs = self.make_connargs()
        cs = ConnectionString.parse(connargs['connection_string'])
        cs.hosts = ['example.com']
        connargs['connection_string'] = cs.encode()
        self.assertRaises(TimeoutException, self.factory, **connargs)

        cs.hosts = [self.cluster_info.host + ':' + str(34567)]
        self.assertRaises(TimeoutException, self.factory, **connargs)
コード例 #4
0
    def test_does_not_encode_slashes(self):
        connstr = ConnectionString.parse(
            'couchbases://10.112.170.101?certpath=/var/rootcert.pem')
        self.assertTrue('certpath' in connstr.options)
        self.assertEqual('/var/rootcert.pem',
                         connstr.options.get('certpath')[0])

        encoded = connstr.encode()
        self.assertEqual(
            'couchbases://10.112.170.101?certpath=/var/rootcert.pem', encoded)
コード例 #5
0
 def setUp(self, **kwargs):
     super(ClusterTestCase, self).setUp()
     connargs = self.cluster_info.make_connargs()
     connstr_abstract = ConnectionString.parse(connargs.pop('connection_string'))
     bucket_name = connstr_abstract.bucket
     connstr_abstract.bucket = None
     connstr_abstract.set_option('enable_collections', 'true')
     self.cluster = self.cluster_factory(connstr_abstract, ClusterOptions(
         ClassicAuthenticator(self.cluster_info.admin_username, self.cluster_info.admin_password)))  # type: Cluster
     # self.admin = self.cluster.admin#self.make_admin_connection()
     self.bucket = self.cluster.bucket(bucket_name, **connargs)
     self.bucket_name = bucket_name
コード例 #6
0
 def _create_cluster_clean(self, authenticator):
     connargs = self.make_connargs()
     connstr = ConnectionString.parse(str(
         connargs.pop('connection_string')))
     connstr.clear_option('username')
     bucket = connstr.bucket
     connstr.bucket = None
     password = connargs.get('password', None)
     keys_to_skip = authenticator.get_credentials(bucket)['options'].keys()
     for entry in keys_to_skip:
         connstr.clear_option(entry)
     cluster = Cluster(connstr, bucket_factory=self.factory)
     cluster.authenticate(ClassicAuthenticator(buckets={bucket: password}))
     return cluster, bucket
コード例 #7
0
    def _create_cluster(self):
        connargs = self.make_connargs()
        connstr = ConnectionString.parse(str(
            connargs.pop('connection_string')))
        connstr.clear_option('username')
        bucket = connstr.bucket
        connstr.bucket = None
        password = connargs.get('password', '')

        # Can I open a new bucket via open_bucket?
        cluster = Cluster(connstr, bucket_factory=self.factory)
        cluster.authenticate(
            ClassicAuthenticator(
                buckets={bucket: password},
                cluster_password=self.cluster_info.admin_password,
                cluster_username=self.cluster_info.admin_username))
        return cluster, bucket
コード例 #8
0
    def test_actions(self):
        if not self.is_realserver:
            raise SkipTest('Real server must be used for admin tests')

        if not os.environ.get('PYCBC_TEST_ADMIN'):
            raise SkipTest('PYCBC_TEST_ADMIN must be set in the environment')

        try:
            # Remove the bucket, if it exists
            self.admin.bucket_remove('dummy')
        except CouchbaseError:
            pass

        # Need to explicitly enable admin tests..
        # Create the bucket
        self.admin.bucket_create(name='dummy',
                                 ram_quota=100,
                                 bucket_password='******')
        self.admin.wait_ready('dummy', timeout=15.0)

        # All should be OK, ensure we can connect:
        connstr = ConnectionString.parse(
            self.make_connargs()['connection_string'])

        connstr.bucket = 'dummy'
        connstr = connstr.encode()
        self.factory(connstr, password='******')
        # OK, it exists
        self.assertRaises(CouchbaseError, self.factory, connstr)

        # Change the password
        self.admin.bucket_update('dummy',
                                 self.admin.bucket_info('dummy'),
                                 bucket_password='')
        self.factory(connstr)  # No password

        # Remove the bucket
        self.admin.bucket_remove('dummy')
        self.assertRaises(CouchbaseError, self.factory, connstr)
コード例 #9
0
    def test_actions(self):

        try:
            # Remove the bucket, if it exists
            self.bm.drop_bucket('dummy')
        except CouchbaseError:
            pass

        # Need to explicitly enable admin tests..
        # Create the bucket
        self.bm.create_bucket(
            CreateBucketSettings(name='dummy',
                                 ram_quota_mb=100,
                                 bucket_password='******'))
        self.bm._admin_bucket.wait_ready('dummy', timeout=15.0)

        # All should be OK, ensure we can connect:
        connstr = ConnectionString.parse(
            self.make_connargs()['connection_string'])

        dummy_bucket = 'dummy'
        connstr = connstr.encode()
        args = self.make_connargs()
        args.pop('connection_string', None)
        args['bucket'] = dummy_bucket
        self.factory(connstr, **args)
        # OK, it exists
        self.assertRaises(CouchbaseError, self.factory, connstr)

        # Change the password

        self.bm.update_bucket(BucketSettings(name=dummy_bucket, max_ttl=500))
        self.bm._admin_bucket.wait_ready(dummy_bucket, 10)
        dummy = self.bm.get_bucket('dummy')
        self.assertEqual(500, dummy.max_ttl)
        # Remove the bucket
        self.bm.drop_bucket('dummy')
        self.assertRaises(CouchbaseError, self.factory, connstr)
コード例 #10
0
 def test_pathless_connstr(self):
     connstr = ConnectionString.parse(
         'couchbase://localhost?opt1=val1&opt2=val2')
     self.assertTrue('opt1' in connstr.options)
     self.assertTrue('opt2' in connstr.options)
コード例 #11
0
 def test_pathless_connstr(self):
     # Not strictly a cluster test, but relevant
     connstr = ConnectionString.parse(
         'couchbase://localhost?opt1=val1&opt2=val2')
     self.assertTrue('opt1' in connstr.options)
     self.assertTrue('opt2' in connstr.options)