Example #1
0
    def __init__(self, database, collection="fs"):
        if not isinstance(database, Database):
            raise TypeError("database must be an instance of Database")

        if not database.write_concern.acknowledged:
            raise ConfigurationError('database must use '
                                     'acknowledged write_concern')

        self.__database = database
        self.__collection = database[collection]
        self.__files = self.__collection.files
        self.__chunks = self.__collection.chunks
Example #2
0
    def __init__(self, db, bucket_name="fs",
                 chunk_size_bytes=DEFAULT_CHUNK_SIZE, write_concern=None,
                 read_preference=None):
        if not isinstance(db, Database):
            raise TypeError("database must be an instance of mongomock Database")

        wtc = write_concern if write_concern is not None else db.write_concern
        if not wtc.acknowledged:
            raise ConfigurationError('write concern must be acknowledged')

        self._db = db
        self._bucket_name = bucket_name
        self._collection = db[bucket_name]

        self._chunks = self._collection.chunks.with_options(
            write_concern=write_concern,
            read_preference=read_preference)

        self._files = self._collection.files.with_options(
            write_concern=write_concern,
            read_preference=read_preference)

        self._chunk_size_bytes = chunk_size_bytes
Example #3
0
    def get_default_database(self):
        if self.__default_datebase_name is None:
            raise ConfigurationError('No default database defined')

        return self[self.__default_datebase_name]