#!/usr/bin/env python from couchbase.admin import Admin from couchbase.bucket import Bucket adm = Admin('Administrator', '123456', host='localhost', port=8091) adm.bucket_create('new-bucket', bucket_type='couchbase', bucket_password='******') # Wait for bucket to become ready adm.wait_ready('new-bucket', timeout=30) bucket = Bucket('couchbase://localhost/new-bucket', password='******') bucket.upsert('foo', 'bar') adm.bucket_remove('new-bucket')
from couchbase.cluster import Cluster from couchbase.bucket import Bucket from couchbase.exceptions import CouchbaseTransientError, HTTPError, KeyExistsError, NotFoundError import couchbase.subdocument as SD from couchbase.n1ql import N1QLQuery # Delete any pre-existing buckets. Create new. cb_adm = Admin(testenv['couchdb_username'], testenv['couchdb_password'], host=testenv['couchdb_host'], port=8091) # Make sure a test bucket exists try: cb_adm.bucket_create('travel-sample') cb_adm.wait_ready('travel-sample', timeout=30) except HTTPError: pass @pytest.mark.skipif("COUCHBASE_TEST" not in os.environ, reason="") class TestStandardCouchDB(unittest.TestCase): def setup_class(self): """ Clear all spans before a test run """ self.recorder = tracer.recorder self.cluster = Cluster('couchbase://%s' % testenv['couchdb_host']) self.bucket = Bucket('couchbase://%s/travel-sample' % testenv['couchdb_host'], username=testenv['couchdb_username'], password=testenv['couchdb_password'])
# The terraform script will out put the IP address ip_f = open('terraform/ip_address.txt') ip = str(ip_f.read()).strip('\n') print('Connecting to Couchbase instance at %s' % (ip)) adm = Admin('Administrator', 'password', host=ip, port=8091) try: adm.bucket_create('commerce') except HTTPError as err: v = err.__dict__['all_results'][None] if 'already exists' in v.value['errors']['name']: print('Bucket already exists, not creating.') adm.wait_ready('commerce', timeout=10) # connect w/ SDK cluster = Cluster('couchbase://' + ip) auth = PasswordAuthenticator('Administrator', 'password') cluster.authenticate(auth) cb = cluster.open_bucket('commerce') # create anlytics indexes queries = [ 'CREATE DATASET ships ON `commerce` WHERE `type` = "ship"', 'CREATE DATASET voyages ON `commerce` WHERE `type` = "voyage"', 'CREATE DATASET customers ON `commerce` WHERE `type` = "customer"', 'CREATE DATASET reservations ON `commerce` WHERE `type` = "reservation"', 'CREATE DATASET credits ON `commerce` WHERE `type` = "credit"', 'CONNECT LINK Local'