def test_mongopool(self):

        copool = []

        self.mp = MongoPool()
        nbmax = self.mp.availableconnection

        # init
        co1 = self.initConnection()
        assert co1 is not None
        copool.append(co1)

        # get connections
        for _ in range(2, nbmax + 1):
            co = self.getConnection()
            assert co is not None
            copool.append(co)

        # should error pool explosed
        co = None
        try:
            co = self.getConnection()
        except Exception:
            assert co is None
        else:
            assert False, 'pool should be full'

        mp = MongoPool()
        assert mp.availableconnection == 0

        # Release cnnection
        for co in copool:
            mp.returnToPool(co)

        assert mp.availableconnection == nbmax
class TestMongoPool(object):
    mp = None
    MAX_CONNECTION = 3

    def getConnection(self):
        self.mp = MongoPool()
        #print mp
        return self.mp.getConnection()

    #useless: overide by infra setup
    def initConnection(self):
        host = Configuration.getworker()['mongo']['host']
        port = Configuration.getworker()['mongo']['port']
        db = Configuration.getworker()['mongo']['db']
        self.mp = MongoPool(host, port, db, self.MAX_CONNECTION)
        #print mp
        return self.mp.getConnection()

    @py.test.mark.fullstack
    def test_mongopool(self):

        copool = []

        self.mp = MongoPool()
        nbmax = self.mp.availableconnection

        # init
        co1 = self.initConnection()
        assert co1 is not None
        copool.append(co1)

        # get connections
        for _ in range(2, nbmax + 1):
            co = self.getConnection()
            assert co is not None
            copool.append(co)

        # should error pool explosed
        co = None
        try:
            co = self.getConnection()
        except Exception:
            assert co is None
        else:
            assert False, 'pool should be full'

        mp = MongoPool()
        assert mp.availableconnection == 0

        # Release cnnection
        for co in copool:
            mp.returnToPool(co)

        assert mp.availableconnection == nbmax
 def initConnection(self):
     host = Configuration.getworker()['mongo']['host']
     port = Configuration.getworker()['mongo']['port']
     db = Configuration.getworker()['mongo']['db']
     self.mp = MongoPool(host, port, db, self.MAX_CONNECTION)
     #print mp
     return self.mp.getConnection()
 def getConnection(self):
     self.mp = MongoPool()
     #print mp
     return self.mp.getConnection()
Exemple #5
0
from sh import cat
from sh import mv
from distark.commons.utils.db.mongopool import MongoPool
from distark.commons.utils.MyConfiguration import Configuration

MODE_DESC='description'
MODE_POINT='points'
MODE_PROPERTIES='prop'
MODE_QTE="qte"
MODE_NOTHING='nothing'

MAX_CONN = 1
host = Configuration.getworker()['mongo']['host']
port = Configuration.getworker()['mongo']['port']
db = Configuration.getworker()['mongo']['db']
mp = MongoPool(host, port, db, MAX_CONN)
dbcon = mp.getConnection()
refloat = re.compile('^\d+(\.\d+)*$')


def is_mode_qte(line):
    res=False
    qte = ['100 g', '1 part', '1 pot', u'1 unité', '1 tranche',
           '1 portion', '100 ml', '1 canette', 'c.c.']
    if line in qte:
        res = True

    return res


def store_data(lst_desc, lst_qte, lst_cal, lst_prot, lst_glu, lst_lip):