def test_default_can_drop_collections_true_only_if_properly_prefixed(self): self.assertFalse(can_drop_collection('foobar')) self.assertFalse(can_drop_collection('foo.bar')) self.assertFalse(can_drop_collection('foo.bar.baz')) self.assertFalse(can_drop_collection('system.users')) prefix = settings.MONGODB_COLLECTIONS_PREFIX self.assertTrue(can_drop_collection('%s.%s' % (prefix, 'foobar'))) self.assertTrue(can_drop_collection('%s.%s' % (prefix, 'foo.bar'))) self.assertTrue(can_drop_collection('%s.%s' % (prefix, 'foo.bar.baz'))) self.assertTrue(can_drop_collection('%s.%s' % (prefix, 'system'))) self.assertTrue(can_drop_collection('%s.%s' % (prefix, 'system.users')))
def clear_all_collections(self): """ Drops all collection that are prefixed with ``settings.MONGODB_COLLECTIONS_PREFIX``. """ for collection_name in self.db.collection_names(): if can_drop_collection(collection_name): self.db.drop_collection(collection_name)
def can_drop_collection(self, collection_name, connection): """ :param collection_name: collection's name, as string :param connection: mongodb connection """ return can_drop_collection(collection_name)