def run_tests(): """Inserts a doc into database a, waits and tries to read it back from database b """ # set things up database = 'replication_notification_test' server_a = client.Server('http://localhost:5984') server_b = client.Server('http://localhost:5985') # server_c = client.Server('http://localhost:5986') db_a = set_up_database(server_a, database) db_b = set_up_database(server_b, database) # db_c = set_up_database(server_c, database) doc = {'jan': 'cool'} docId = 'testdoc' # add doc to node a db_a[docId] = doc # wait a bit. Adjust depending on your --wait-threshold setting time.sleep(5) # read doc from node b and compare to a try: db_b[docId] == db_a[docId] # == db_c[docId] print 'SUCCESS at reading it back from database "b"' except client.ResourceNotFound: print 'FAILURE at reading it back from database "b"'
def setUp(self): uri = os.environ.get('COUCHDB_URI', 'http://localhost:5984/') self.server = client.Server(uri) try: self.server.delete('python-tests') except client.ResourceNotFound: pass self.db = self.server.create('python-tests')
def setUp(self): uri = os.environ.get('COUCHDB_URI', client.DEFAULT_BASE_URI) self.server = client.Server(uri) try: self.server.delete('python-tests') except client.ResourceNotFound: pass self.db = self.server.create('python-tests')
def test_user_management(self): url = client.DEFAULT_BASE_URL if not isinstance(url, util.utype): url = url.decode('utf-8') server = client.Server(url) try: server.add_user('foo', 'secret', roles=['hero']) token = server.login('foo', 'secret') self.assertTrue(server.verify_token(token)) self.assertTrue(server.logout(token)) finally: server.remove_user('foo')
def test_235_unicode_server(self): url = client.DEFAULT_BASE_URL if not isinstance(url, util.utype): url = url.decode('utf-8') server = client.Server(url) dbname = 'couchdb-python/test-235-unicode-server' db = server.create(dbname) try: db.update([{'foo': u'\ua000'}]) finally: server.delete(dbname)
def test_exists(self): self.assertTrue(client.Server(client.DEFAULT_BASE_URL)) self.assertFalse(client.Server('http://localhost:9999'))
def test_init_with_session(self): sess = http.Session() serv = client.Server(client.DEFAULT_BASE_URL, session=sess) serv.config() self.assertTrue(serv.resource.session is sess)
def test_init_with_resource(self): sess = http.Session() res = http.Resource(client.DEFAULT_BASE_URL, sess) serv = client.Server(url=res) serv.config()
def test_basic_auth(self): url = "http://*****:*****@localhost:5984/" server = client.Server(url) dbname = 'couchdb-python/test_basic_auth' self.assertRaises(http.Unauthorized, server.create, dbname)
def setUp(self): self.server = client.Server(full_commit=False)
def main(): usage = '%prog [options] <source> <target>' parser = optparse.OptionParser(usage=usage) parser.add_option('--continuous', action='store_true', dest='continuous', help='trigger continuous replication in cochdb') parser.add_option('--compact', action='store_true', dest='compact', help='compact target database after replication') options, args = parser.parse_args() if len(args) != 2: raise parser.error('need source and target arguments') # set up server objects src, tgt = args sbase, spath = findpath(parser, src) source = client.Server(sbase) tbase, tpath = findpath(parser, tgt) target = client.Server(tbase) # check database name specs if '*' in tpath: raise parser.error('invalid target path: must be single db or empty') elif '*' in spath and tpath: raise parser.error('target path must be empty with multiple sources') all = sorted(i for i in source if i[0] != '_') # Skip reserved names. if not spath: raise parser.error('source database must be specified') databases = [(i, i) for i in all if fnmatch.fnmatchcase(i, spath)] if not databases: raise parser.error("no source databases match glob '%s'" % spath) # do the actual replication for sdb, tdb in databases: start = time.time() print( sdb, '->', tdb, ) sys.stdout.flush() if tdb not in target: target.create(tdb) print("created", ) sys.stdout.flush() sdb = '%s%s' % (sbase, urllib.quote(sdb, '')) if options.continuous: target.replicate(sdb, tdb, continuous=options.continuous) else: target.replicate(sdb, tdb) print('%.1fs' % (time.time() - start)) sys.stdout.flush() if options.compact: for (sdb, tdb) in databases: print('compact', tdb) target[tdb].compact()
def setUp(self): uri = os.environ.get('COUCHDB_URI', client.DEFAULT_BASE_URI) self.server = client.Server(uri)
def __init__(self): self.couch = client.Server() self.db = self.couch['customer'] self.bs = Bootstrapper()
FLICKR_USER_ID = getattr(settings, 'FLICKR_USER_ID', None) GITHUB_USERNAME = getattr(settings, 'GITHUB_USERNAME', None) DIGG_USERNAME = getattr(settings, 'DIGG_USERNAME', None) YOUTUBE_USERNAME = getattr(settings, 'YOUTUBE_USERNAME', None) LASTFM_USERNAME = getattr(settings, 'LASTFM_USERNAME', None) PANDORA_USERNAME = getattr(settings, 'PANDORA_USERNAME', None) READERNAUT_USERNAME = getattr(settings, 'READERNAUT_USERNAME', None) DELICIOUS_USERNAME = getattr(settings, 'DELICIOUS_USERNAME', None) DISQUS_USERNAME = getattr(settings, 'DISQUS_USERNAME', None) USERNAMES = dict( TWITTER=TWITTER_USERNAME, POWNCE=POWNCE_USERNAME, REDDIT=REDDIT_USERNAME, FLICKR=FLICKR_USER_ID, GITHUB=GITHUB_USERNAME, DIGG=DIGG_USERNAME, YOUTUBE=YOUTUBE_USERNAME, LASTFM=LASTFM_USERNAME, PANDORA=PANDORA_USERNAME, READERNAUT=READERNAUT_USERNAME, DELICIOUS=DELICIOUS_USERNAME, DISQUS=DISQUS_USERNAME, ) server = client.Server(HOST) try: db = server.create(DATABASE_NAME) except (client.ResourceConflict, client.ServerError): db = server[DATABASE_NAME]