Esempio n. 1
0
 def test_uri_connect(self):
     conn = connect(uri="mongodb://localhost/%s" % DBNAME)
     self.assertTrue(isinstance(conn, pymongo.Connection))
     connection = Connection.instance()
     self.assertEqual(connection._database, DBNAME)
     conn.disconnect()
     # overriding the database name
     conn = connect(DBNAME, uri="mongodb://localhost/foobar")
     self.assertTrue(isinstance(conn, pymongo.Connection))
     connection = Connection.instance()
     self.assertEqual(connection._database, DBNAME)
     conn.disconnect()
Esempio n. 2
0
 def test_uri_connect(self):
     conn = connect(uri="mongodb://localhost/%s" % DBNAME)
     self.assertTrue(isinstance(conn, pymongo.MongoClient))
     connection = Connection.instance()
     self.assertEqual(connection._database, DBNAME)
     conn.close()
     # overriding the database name
     conn = connect(DBNAME, uri="mongodb://localhost/foobar")
     self.assertTrue(isinstance(conn, pymongo.MongoClient))
     connection = Connection.instance()
     self.assertEqual(connection._database, DBNAME)
     conn.close()
Esempio n. 3
0
 def test_uri_connect(self):
     conn = connect(uri="mongodb://localhost/%s" % DBNAME)
     self.assertIsInstance(conn, pymongo.MongoClient)
     connection = Connection.instance()
     self.assertEqual(connection._database, DBNAME)
     conn.close()
     # overriding the database name
     conn = connect(DBNAME, uri="mongodb://localhost/foobar")
     self.assertIsInstance(conn, pymongo.MongoClient)
     connection = Connection.instance()
     self.assertEqual(connection._database, DBNAME)
     conn.close()
Esempio n. 4
0
 def _get_collection(cls):
     """ Connects and caches the collection connection object. """
     if not cls._collection:
         conn = Connection.instance()
         coll = conn.get_collection(cls._get_name())
         cls._collection = coll
     return cls._collection
Esempio n. 5
0
 def _get_collection(cls):
     """ Connects and caches the collection connection object. """
     if not cls._collection:
         conn = Connection.instance()
         coll = conn.get_collection(cls._get_name())
         cls._collection = coll
     return cls._collection
Esempio n. 6
0
    def lookup(cls, query, page=0, limit=5):
        db = mogo_connection.instance().get_database()
        qterms = [t.lower().strip() for t in query.split()]
        skip = limit * page
        retrieve_size = 80  # may need to be tuned
        intermediate = {}

        r = "|".join(["%s" % re.escape(r) for r in qterms])
        regx = re.compile(r, re.IGNORECASE)
        q_lc = [q.lower() for q in qterms]
        users = (
            User.find({"$or": [{"name": {"$regex": regx}}, {"nick_l": {"$in": q_lc}}]})
            .sort([["nick_l", ASCENDING]])
            .limit(int(retrieve_size))
        )

        ret_ = []
        for u in users:
            ret_.append(u)

        numpages = len(ret_) / float(limit)
        ret_ = ret_[skip : skip + limit]

        retvals = []
        for u in ret_:
            retvals.append({"nk": u.nick_l, "nm": u.long_name, "av": u.avatar_url()})

        return retvals, numpages
    def lookup(cls, query, page=0, limit=5):
        db = mogo_connection.instance().get_database()
        qterms = [ t.lower().strip() for t in query.split() ]
        skip = limit * page
        retrieve_size = 80 # may need to be tuned
        intermediate = {}

        r = '|'.join([ "%s" % re.escape(r) for r in qterms ])
        regx = re.compile(r,re.IGNORECASE)
        q_lc = [ q.lower() for q in qterms ]
        users = User.find({
                '$or':[
                    {'name': {'$regex': regx}},
                    {'nick_l': {'$in': q_lc}}
                    ]
            }).sort([['nick_l', ASCENDING]]).limit(int(retrieve_size))


        ret_ = []
        for u in users:
            ret_.append(u)


        numpages = len(ret_)/float(limit)
        ret_ = ret_[skip: skip+limit]

        retvals = []
        for u in ret_:
            retvals.append({
                'nk': u.nick_l,
                'nm': u.long_name,
                'av': u.avatar_url(),
                })

        return retvals, numpages
Esempio n. 8
0
    def connect_to_db(self, db_name=None):
        if db_name is None:
            db_name = settings.TEST_DATABASE
        self.db_conn = connect(db_name)
        self.db_sync = self.db_conn[db_name]
        self.db = Db.getInstance(db_name, pool_size=1).db

        # self.db_conn.drop_database(db_name)
        db = Connection.instance().get_database()
        for col in db.collection_names(include_system_collections=False):
            if not col.startswith('_'):
                db.drop_collection(col)
Esempio n. 9
0
 def test_connect(self):
     self.assertRaises(ValueError, connect)
     self.assertTrue(isinstance(self._conn, pymongo.MongoClient))
     connection = Connection.instance()
     self.assertTrue(connection._database == DBNAME)
     self._conn.close()
Esempio n. 10
0
 def test_connect(self):
     self.assertRaises(TypeError, connect)
     self.assertTrue(isinstance(self._conn, pymongo.Connection))
     connection = Connection.instance()
     self.assertTrue(connection._database == DBNAME)
     self._conn.disconnect()
Esempio n. 11
0
 def test_connect(self):
     self.assertRaises(ValueError, connect)
     self.assertIsInstance(self._conn, pymongo.MongoClient)
     connection = Connection.instance()
     self.assertEqual(connection._database, DBNAME)
     self._conn.close()
Esempio n. 12
0
 def test_connect(self):
     self.assertRaises(TypeError, connect)
     self.assertTrue(isinstance(self._conn, pymongo.Connection))
     connection = Connection.instance()
     self.assertTrue(connection._database == DBNAME)
     self._conn.disconnect()
Esempio n. 13
0
 def test_connect(self):
     self.assertRaises(ValueError, connect)
     self.assertIsInstance(self._conn, pymongo.MongoClient)
     connection = Connection.instance()
     self.assertEqual(connection._database, DBNAME)
     self._conn.close()
Esempio n. 14
0
 def test_connect(self):
     conn = connect(DBNAME)
     self.assertTrue(isinstance(conn, pymongo.Connection))
     connection = Connection.instance()
     self.assertTrue(connection._database == DBNAME)
     conn.disconnect()