Python couchdb.Server() Examples

The following are 13 code examples of couchdb.Server(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module couchdb , or try the search function .
Example #1
Source File: conftest.py    From openprocurement.auction with Apache License 2.0 6 votes vote down vote up
def db(request):
    server = couchdb.Server("http://" + worker_defaults['COUCH_DATABASE'].split('/')[2])
    name = worker_defaults['COUCH_DATABASE'].split('/')[3]

    documents = getattr(request, 'param', None)

    def delete():
        del server[name]

    if name in server:
        delete()

    data_base = server.create(name)

    if documents:
        for doc in documents:
            data_base.save(doc)
            
    request.addfinalizer(delete)

    return data_base 
Example #2
Source File: conftest.py    From openprocurement.auction with Apache License 2.0 6 votes vote down vote up
def auctions_server(request):
    params = getattr(request, 'param', {})
    server_config = params.get('server_config', {})

    logger = MagicMock(spec_set=frontend.logger)
    logger.name = server_config.get('logger_name', 'some-logger')
    frontend.logger_name = logger.name
    frontend._logger = logger

    for key in ('limit_replications_func', 'limit_replications_progress'):
        frontend.config.pop(key, None)

    for key in ('limit_replications_func', 'limit_replications_progress'):
        if key in server_config:
            frontend.config[key] = server_config[key]

    frontend.couch_server = MagicMock(spec_set=Server)
    frontend.config['TIMEZONE'] = 'some_time_zone'

    if 'couch_tasks' in params:
        frontend.couch_server.tasks.return_value = params['couch_tasks']

    test_app = TestApp(frontend)
    return {'app': frontend, 'test_app': test_app} 
Example #3
Source File: couchdb_handler.py    From fake2db with GNU General Public License v2.0 6 votes vote down vote up
def database_caller_creator(self, name=None):
        '''creates a couchdb database
        returns the related connection object
        which will be later used to spawn the cursor
        '''

        couch = couchdb.Server()

        if name:
            db = couch.create(name)
        else:
            n = 'couchdb_' + lower_str_generator(self)
            db = couch.create(n)
            logger.warning('couchdb database created with the name: %s', n,
                           extra=d)

        return db 
Example #4
Source File: checker.py    From root-2015-tasks with GNU General Public License v3.0 6 votes vote down vote up
def __call__(self, doc):
        if self.couch is None:
            self.couch = couchdb.Server("http://%s:5984" % SERVER)

        docid = doc['_id']
        db = (self.couch['words'], self.couch['words_slave'])
        doc1 = db[0][docid]
        doc2 = db[1][docid]
        if doc['t'] != doc1['t'] or doc1['t'] != doc2['t']:
            #print >>sys.stderr, "{0}\n{1}\n{2}".format(doc, doc1, doc2)
            return (FAIL, "Err with doc: {0}".format(docid), (doc, doc1, doc2))

        if doc['word'] != doc1['word'] or doc1['word'] != doc2['word']:
            #print >>sys.stderr, "{0}\n{1}\n{2}".format(doc, doc1, doc2)
            return (FAIL, "Err with doc: {0}".format(docid), (doc, doc1, doc2))

        return (OK, OK, OK) 
Example #5
Source File: checker.py    From root-2015-tasks with GNU General Public License v3.0 6 votes vote down vote up
def check_database(server):
    try:
        etalon_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "etalon.json")
        etalon = json.load(open(etalon_path, "r"))
        couch = couchdb.Server("http://%s:5984" % server)
        db = (couch['words'], couch['words_slave'])

        p = Pool(30)
        result = p.map(CheckDoc(), etalon)
        for r in result:
            if r[0] != OK:
                print r[1]
                print >>sys.stderr, r[2]
                return FAIL

        return OK

    except Exception as e:
        print "Exception: {0}".format(e)
        return FAIL 
Example #6
Source File: couch.py    From arches with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self):
        self.couch = couchdb.Server(settings.COUCHDB_URL) 
Example #7
Source File: couch.py    From openprocurement.auction with Apache License 2.0 5 votes vote down vote up
def couchdb_dns_query_settings(server_url, database_name):
    parsed_url = urlparse(server_url)
    all_ips = set([str(i[4][0]) for i in socket.getaddrinfo(urlparse(server_url).hostname, 80)])

    while all_ips:
        selected_ip = set(sample(all_ips, 1))
        all_ips -= selected_ip
        couch_url = server_url.replace(parsed_url.hostname, selected_ip.pop())
        try:
            server = Server(couch_url, session=Session(retry_delays=range(10)))
            return server[database_name]
        except socket.error:
            continue
    raise Exception("No route to any couchdb server") 
Example #8
Source File: check_configuration_verify_auth.py    From DbDat with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, parent):
        print('Performing check: ' + self.TITLE)
        import couchdb
        from urlparse import urlparse

        # parent connection is authenticated so create a new unauthenticated connection
        url     = urlparse(parent.dbhost)
        self.db = couchdb.Server(url.scheme + '://' + url.hostname + ':' + parent.dbport) 
Example #9
Source File: health.py    From openprocurement.api with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.db_name += uuid4().hex
        # self.couchdb_server.create(self.db_name)
        couchdb_server = Mock(spec=CouchdbServer)
        couchdb_server.tasks = MagicMock(return_value=self.return_value)
        self.app.app.registry.couchdb_server = couchdb_server
        self.db_name = self.db.name
        self.app.authorization = ('Basic', ('token', '')) 
Example #10
Source File: couchdbwalletstore.py    From fabric-sdk-py with Apache License 2.0 5 votes vote down vote up
def __init__(self, dbName, config='http://localhost:5984'):
        self.server = couchdb.Server(config)
        try:
            self.db = self.server[dbName]
        except Exception:
            self.db = self.server.create(dbName) 
Example #11
Source File: TempChart.py    From mvp with MIT License 5 votes vote down vote up
def getResults(test=False):
    '''Run a Mango query to get the data'''
    ts = datetime.utcnow().isoformat()[:19]
    payload={"selector":{"start_date.timestamp":{"$lt":ts}, "status.status_qualifier":"Success", "activity_type":"Environment_Observation", "subject.name":"Air","subject.attribute.name": "Temperature"}, "fields":["start_date.timestamp", "subject.attribute.value"], "sort":[{"start_date.timestamp":"desc"}], "limit":250}    
    db_name = 'mvp_data'
    if test:
        print payload
    server = Server()
    db = server[db_name]
    return db.find(payload) 
Example #12
Source File: DewpointChart.py    From mvp with MIT License 5 votes vote down vote up
def getResults():
#    header={"Content-Type":"application/json"}
    ts = datetime.utcnow().isoformat()[:19]
    payload={"selector":{"start_date.timestamp":{"$lt":ts},"status.status_qualifier":{"$eq": "Success"}, "activity_type":{"$eq":"Environment_Observation"}, "subject.name":{"$eq": "Air"}, "$or":[{"subject.attribute.name":"Humidity"}, {"subject.attribute.name":"Temperature"}]}, "fields":["start_date.timestamp", "subject.attribute.name", "subject.attribute.value"], "sort":[{"start_date.timestamp":"desc"}], "limit":250}        
    server = Server()
    db_name = 'mvp_data'
    db = server[db_name]
    return db.find(payload) 
Example #13
Source File: HumidityChart.py    From mvp with MIT License 5 votes vote down vote up
def getResults(test=False):
    '''Run a Mango query to get the data'''
    ts = datetime.utcnow().isoformat()[:19]
    payload={"selector":{"start_date.timestamp":{"$lt":ts}, "status.status_qualifier":"Success", "activity_type":"Environment_Observation", "subject.name":"Air","subject.attribute.name": "Humidity"}, "fields":["start_date.timestamp", "subject.attribute.value"], "sort":[{"start_date.timestamp":"desc"}], "limit":250}        
    db_name = 'mvp_data'
    if test:
        print payload
    server = Server()
    db = server[db_name]
    return db.find(payload)