def test_updates_collection_list(self):
        with self.real_app.app_context():
            db = get_db()
            res_id = 'myresid.'

            # Setup resource id record
            clients_collection = db[CLIENTS_COLLECTION]
            clients_collection.remove({'res_id': res_id})
            clients_collection.insert({'res_id': res_id, 'collections': []})

            with UseResId(res_id) as db:
                self.assertItemsEqual(get_collection_names(res_id), [])
                db.foo.insert({'message': 'test'})
                self.assertItemsEqual(get_collection_names(res_id), ['foo'])
                self.assertItemsEqual(list(db.foo.find({}, {'_id': 0})),
                                      [{
                                          'message': 'test'
                                      }])

                db.bar.update({}, {'message': 'test'}, upsert=True)
                self.assertItemsEqual(get_collection_names(res_id),
                                      ['foo', 'bar'])
                self.assertItemsEqual(list(db.bar.find({}, {'_id': 0})),
                                      [{
                                          'message': 'test'
                                      }])

                db.foo.drop()
                self.assertItemsEqual(get_collection_names(res_id), ['bar'])
                self.assertNotIn(res_id + 'foo', get_collection_names(res_id))
Example #2
0
    def test_updates_collection_list(self):
        with self.real_app.app_context():
            db = get_db()
            res_id = 'myresid.'

            # Setup resource id record
            clients_collection = db[CLIENTS_COLLECTION]
            clients_collection.remove({'res_id': res_id})
            clients_collection.insert({
                'res_id': res_id,
                'collections': []
            })

            with UseResId(res_id) as db:
                self.assertItemsEqual(get_collection_names(res_id), [])
                db.foo.insert({'message': 'test'})
                self.assertItemsEqual(get_collection_names(res_id), ['foo'])
                self.assertItemsEqual(list(db.foo.find({}, {'_id': 0})),
                                      [{'message': 'test'}])

                db.bar.update({}, {'message': 'test'}, upsert=True)
                self.assertItemsEqual(get_collection_names(res_id), ['foo', 'bar'])
                self.assertItemsEqual(list(db.bar.find({}, {'_id': 0})),
                                      [{'message': 'test'}])

                db.foo.drop()
                self.assertItemsEqual(get_collection_names(res_id), ['bar'])
                self.assertNotIn(res_id + 'foo', get_collection_names(res_id))
Example #3
0
def db_drop(res_id):
    DB = get_db()
    collections = get_collection_names(res_id)
    with UseResId(res_id):
        for c in collections:
            DB.drop_collection(c)
        return empty_success()
Example #4
0
def db_drop(res_id):
    DB = get_db()
    collections = get_collection_names(res_id)
    with UseResId(res_id):
        for c in collections:
            DB.drop_collection(c)
        return empty_success()
Example #5
0
 def setUp(self):
     super(QuotaCollectionsTestCase, self).setUp()
     self.old_quota = self.real_app.config['QUOTA_NUM_COLLECTIONS']
     self.res_id = 'myresid.'
     with self.real_app.app_context():
         collections = get_collection_names(self.res_id)
         with UseResId(self.res_id) as db:
             for c in collections:
                 db.drop_collection(c)
 def setUp(self):
     super(QuotaCollectionsTestCase, self).setUp()
     self.old_quota = self.real_app.config['QUOTA_NUM_COLLECTIONS']
     self.res_id = 'myresid.'
     with self.real_app.app_context():
         collections = get_collection_names(self.res_id)
         with UseResId(self.res_id) as db:
             for c in collections:
                 db.drop_collection(c)
Example #7
0
    def test_drop_db(self):
        testdoc = {'name': 'Mongo'}
        colls = ['a', 'b', 'c']
        update = {'$addToSet': {'collections': {'$each': colls}}}
        self.db[CLIENTS_COLLECTION].update({'res_id': self.res_id}, update)
        colls = [to_coll_name(self.res_id, c) for c in colls]
        for col in colls:
            self.db[col].insert(testdoc)

        actual_colls = self.db.collection_names()
        for col in colls:
            self.assertIn(col, actual_colls)

        self.make_db_drop_request()

        actual_colls = self.db.collection_names()
        for col in colls:
            self.assertNotIn(col, actual_colls)

        self.assertItemsEqual(get_collection_names(self.res_id), [])
Example #8
0
    def test_drop_db(self):
        testdoc = {'name': 'Mongo'}
        colls = ['a', 'b', 'c']
        update = {'$addToSet': {'collections': {'$each': colls}}}
        self.db[CLIENTS_COLLECTION].update({'res_id': self.res_id}, update)
        colls = [to_coll_name(self.res_id, c) for c in colls]
        for col in colls:
            self.db[col].insert(testdoc)

        actual_colls = self.db.collection_names()
        for col in colls:
            self.assertIn(col, actual_colls)

        self.make_db_drop_request()

        actual_colls = self.db.collection_names()
        for col in colls:
            self.assertNotIn(col, actual_colls)

        self.assertItemsEqual(get_collection_names(self.res_id), [])
Example #9
0
    def test_drop_db(self):
        testdoc = {"name": "Mongo"}
        colls = ["a", "b", "c"]
        update = {"$addToSet": {"collections": {"$each": colls}}}
        self.db[CLIENTS_COLLECTION].update({"res_id": self.res_id}, update)
        colls = [get_internal_coll_name(self.res_id, c) for c in colls]
        for c in colls:
            self.db[c].insert(testdoc)

        actual_colls = self.db.collection_names()
        for c in colls:
            self.assertIn(c, actual_colls)

        self.make_db_drop_request()

        actual_colls = self.db.collection_names()
        for c in colls:
            self.assertNotIn(c, actual_colls)

        self.assertItemsEqual(get_collection_names(self.res_id), [])
Example #10
0
def db_get_collection_names(res_id):
    return to_json({'result': get_collection_names(res_id)})
Example #11
0
def db_get_collection_names(res_id):
    return to_json({'result': get_collection_names(res_id)})
Example #12
0
def cleanup_collections(res_id):
    db = get_db()
    for coll in get_collection_names(res_id):
        with UseResId(res_id):
            _logger.info('dropping %s', coll)
            db.drop_collection(coll)
Example #13
0
def cleanup_collections(res_id):
    db = get_db()
    for coll in get_collection_names(res_id):
        with UseResId(res_id):
            _logger.info('dropping %s', coll)
            db.drop_collection(coll)