예제 #1
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()
예제 #2
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():
         self.db = get_db()
         collections = get_collection_names(self.res_id)
         with UseResId(self.res_id):
             for c in collections:
                 self.db.drop_collection(c)
예제 #3
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():
         self.db = get_db()
         collections = get_collection_names(self.res_id)
         with UseResId(self.res_id):
             for c in collections:
                 self.db.drop_collection(c)
예제 #4
0
    def test_loads_dumped_bson_data(self, os_mock, Popen_mock):
        popen_instance = mock.MagicMock()
        popen_instance.poll.return_value = 0
        Popen_mock.return_value = popen_instance
        os_mock.path.exists.return_value = True

        with self.real_app.app_context():
            res_id = 'myresid.'
            collection_name = 'collname'
            dump_location = '/my/dump/location'
            load_data_from_mongodump(res_id, dump_location, collection_name)
            Popen_mock.assert_called_with(
                ('mongorestore', '-d', 'mws', '-c',
                 '%s%s' % (res_id, collection_name), dump_location))
            popen_instance.communicate.assert_called_once_with()  # no args
            self.assertIn(collection_name, get_collection_names(res_id))
예제 #5
0
    def test_loads_dumped_bson_data(self, os_mock, Popen_mock):
        popen_instance = mock.MagicMock()
        popen_instance.poll.return_value = 0
        Popen_mock.return_value = popen_instance
        os_mock.path.exists.return_value = True

        with self.real_app.app_context():
            res_id = 'myresid.'
            collection_name = 'collname'
            dump_location = '/my/dump/location'
            load_data_from_mongodump(res_id, dump_location, collection_name)
            Popen_mock.assert_called_with((
                'mongorestore',
                '-d', 'mws',
                '-c', '%s%s' % (res_id, collection_name),
                dump_location
            ))
            popen_instance.communicate.assert_called_once_with()  # no args
            self.assertIn(collection_name, get_collection_names(res_id))
예제 #6
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), [])
예제 #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 = [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), [])
예제 #8
0
def db_get_collection_names(res_id):
    return to_json({'result': get_collection_names(res_id)})