Exemple #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()
 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)
Exemple #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)
Exemple #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))
    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))
    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), [])
    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), [])
Exemple #8
0
def db_get_collection_names(res_id):
    return to_json({'result': get_collection_names(res_id)})